public class XWalkUpdater
extends java.lang.Object
XWalkUpdater is a follow-up solution for XWalkInitializer in case the
initialization has failed. The users of XWalkActivity don't need to use this class.
XWalkUpdater helps to donwload the Crosswalk runtime and displays dialogs to
interact with the user. By default, it will navigate to the Crosswalk runtime's page on the
default application store, subsequent process will be up to the user. If the developer specified
the download URL of the Crosswalk runtime, it will launch the download manager to fetch the APK.
To specify the download URL, insert a meta-data element with the name "xwalk_apk_url" inside the
application tag in the Android manifest.
<application android:name="org.xwalk.core.XWalkApplication">
<meta-data android:name="xwalk_apk_url" android:value="http://host/XWalkRuntimeLib.apk" />
After the proper Crosswalk runtime is downloaded and installed, the user will return to
current activity from the application store or the installer. The developer should check this
point and invoke XWalkInitializer.initAsync() again to repeat the initialization
process. Please note that from now on, the application will be running in shared mode.
For example:
public class MyActivity extends Activity
implements XWalkInitializer.XWalkInitListener, XWalkUpdater.XWalkUpdateListener {
XWalkUpdater mXWalkUpdater;
......
@Override
protected void onResume() {
super.onResume();
// Try to initialize again when the user completed updating and returned to current
// activity. The initAsync() will do nothing if the initialization has already been
// completed successfully.
mXWalkInitializer.initAsync();
}
@Override
public void onXWalkInitFailed() {
if (mXWalkUpdater == null) mXWalkUpdater = new mXWalkUpdater(this, this);
// The updater won't be launched if previous update dialog is showing.
mXWalkUpdater.updateXWalkRuntime();
}
@Override
public void onXWalkUpdateCancelled() {
// Perform error handling here
}
}
To download the Crosswalk runtime, you need to grant following permissions in the Android manifest:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
| Modifier and Type | Class and Description |
|---|---|
static interface |
XWalkUpdater.XWalkUpdateListener
Interface used to update the Crosswalk runtime
|
| Constructor and Description |
|---|
XWalkUpdater(XWalkUpdater.XWalkUpdateListener listener,
android.app.Activity activity)
Create XWalkUpdater for single activity
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
dismissDialog()
Dismiss the dialog showing and waiting for user's input.
|
void |
setXWalkApkUrl(java.lang.String url)
Set the download URL of the Crosswalk runtime.
|
boolean |
updateXWalkRuntime()
Update the Crosswalk runtime.
|
public XWalkUpdater(XWalkUpdater.XWalkUpdateListener listener, android.app.Activity activity)
listener - The XWalkUpdater.XWalkUpdateListener to useactivity - The activity which initiate the updatepublic boolean updateXWalkRuntime()
Please try to initialize by XWalkInitializer first and only invoke this method
when the initialization failed. This method must be invoked on the UI thread.
public boolean dismissDialog()
public void setXWalkApkUrl(java.lang.String url)
url - The download URL.