Index: chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java |
diff --git a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java |
index a99304ef3b8417a86aed263f9a72749595574467..a2a62a32c9e9d47466f3c17ad5dccb561faf9d84 100644 |
--- a/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java |
+++ b/chrome/android/webapk/shell_apk/src/org/chromium/webapk/shell_apk/MainActivity.java |
@@ -6,7 +6,7 @@ package org.chromium.webapk.shell_apk; |
import android.app.Activity; |
import android.content.ActivityNotFoundException; |
-import android.content.Context; |
+import android.content.ComponentName; |
import android.content.Intent; |
import android.content.pm.ApplicationInfo; |
import android.content.pm.PackageManager; |
@@ -18,7 +18,6 @@ import android.util.Log; |
import org.chromium.webapk.lib.common.WebApkConstants; |
import org.chromium.webapk.lib.common.WebApkMetaDataKeys; |
-import java.lang.reflect.Method; |
import java.net.URISyntaxException; |
/** |
@@ -64,13 +63,13 @@ public class MainActivity extends Activity { |
* Launches WebAPK. |
*/ |
private void launch() { |
- if (launchHostBrowserInWebApkMode()) { |
- return; |
- } |
String startUrl = getStartUrl(); |
if (startUrl == null) { |
return; |
} |
+ if (launchHostBrowserInWebApkMode(startUrl)) { |
+ return; |
+ } |
if (launchBrowser(startUrl)) { |
return; |
} |
@@ -81,25 +80,25 @@ public class MainActivity extends Activity { |
* Launches host browser in WebAPK mode. |
* @return True if successful. |
*/ |
- private boolean launchHostBrowserInWebApkMode() { |
- ClassLoader webApkClassLoader = HostBrowserClassLoader.getClassLoaderInstance( |
- this, HOST_BROWSER_LAUNCHER_CLASS_NAME); |
- if (webApkClassLoader == null) { |
- Log.w(TAG, "Unable to create ClassLoader."); |
- return false; |
- } |
+ private boolean launchHostBrowserInWebApkMode(String startUrl) { |
+ Log.v(TAG, "Url of the WebAPK: " + startUrl); |
+ String packageName = getPackageName(); |
+ Log.v(TAG, "Package name of the WebAPK:" + packageName); |
+ |
+ String runtimeHost = WebApkUtils.getHostBrowserPackageName(this); |
+ int source = getIntent().getIntExtra(WebApkConstants.EXTRA_SOURCE, 0); |
+ Intent intent = new Intent(); |
+ intent.setComponent(new ComponentName( |
+ runtimeHost, "org.chromium.chrome.browser.webapps.WebappLauncherActivity")); |
+ intent.putExtra(WebApkConstants.EXTRA_ID, WebApkConstants.WEBAPK_ID_PREFIX + packageName) |
+ .putExtra(WebApkConstants.EXTRA_URL, startUrl) |
+ .putExtra(WebApkConstants.EXTRA_SOURCE, source) |
+ .putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, packageName); |
try { |
- Class<?> hostBrowserLauncherClass = |
- webApkClassLoader.loadClass(HOST_BROWSER_LAUNCHER_CLASS_NAME); |
- Method launchMethod = hostBrowserLauncherClass.getMethod( |
- "launch", Context.class, Intent.class, Bundle.class); |
- Object hostBrowserLauncherInstance = hostBrowserLauncherClass.newInstance(); |
- Bundle bundle = new Bundle(); |
- bundle.putInt(KEY_APP_ICON_ID, R.mipmap.app_icon); |
- launchMethod.invoke(hostBrowserLauncherInstance, this, getIntent(), bundle); |
+ startActivity(intent); |
return true; |
- } catch (Exception e) { |
+ } catch (ActivityNotFoundException e) { |
Log.w(TAG, "Unable to launch browser in WebAPK mode."); |
e.printStackTrace(); |
return false; |