private void downloadXWalkApk() { // The download url is defined by the meta-data element with the name "xwalk_apk_url" // inside the application tag in the Android manifest. It can also be specified via // the option --xwalk-apk-url of the script make_apk. if (mXWalkApkUrl == null) { mXWalkApkUrl = getXWalkApkUrl(); Log.d(TAG, "Crosswalk APK download URL: " + mXWalkApkUrl); } if (!mXWalkApkUrl.isEmpty()) { XWalkLibraryLoader.startDownload(new ForegroundListener(), mActivity, mXWalkApkUrl); return; } try { Intent intent = new Intent(Intent.ACTION_VIEW); mActivity.startActivity(intent.setData(Uri.parse(XWALK_APK_MARKET_URL))); Log.d(TAG, "Market opened"); mDialogManager.dismissDialog(); } catch (ActivityNotFoundException e) { Log.d(TAG, "Market open failed"); mDialogManager.showMarketOpenError(mCancelCommand); } }
/** * Update the Crosswalk runtime. There are 2 ways to download the Crosswalk runtime: from the play * store or the specified URL. It will download from the play store if the download URL is not * specified. To specify the download URL, insert a meta-data element with the name * "xwalk_apk_url" inside the application tag in the Android manifest. * * <p>Please try to initialize by {@link XWalkInitializer} first and only invoke this method when * the initialization failed. This method must be invoked on the UI thread. * * @return True if the updater is launched, false if is in updating, or the Crosswalk runtime * doesn't need to be updated, or the Crosswalk runtime has not been initialized yet. */ public boolean updateXWalkRuntime() { if (mIsDownloading || (mDialogManager != null && mDialogManager.isShowingDialog())) { return false; } int status = XWalkLibraryLoader.getLibraryStatus(); if (status == XWalkLibraryInterface.STATUS_PENDING || status == XWalkLibraryInterface.STATUS_MATCH) return false; if (mUpdateListener != null) { mDownloadCommand = new Runnable() { @Override public void run() { downloadXWalkApk(); } }; mCancelCommand = new Runnable() { @Override public void run() { Log.d(TAG, "XWalkUpdater cancelled"); mUpdateListener.onXWalkUpdateCancelled(); } }; mDialogManager.showInitializationError(status, mCancelCommand, mDownloadCommand); } else if (mBackgroundUpdateListener != null) { downloadXWalkApkSilently(); } else { Assert.fail(); } return true; }
/** * Dismiss the dialog showing and waiting for user's input. * * @return Return false if no dialog is being displayed, true if dismissed the showing dialog. */ public boolean dismissDialog() { if (mDialogManager == null || !mDialogManager.isShowingDialog()) return false; mDialogManager.dismissDialog(); return true; }