Index: chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
index ddc209fa234981cf6ea007e9db8673f44f256146..116317a82126b4c47c34399f87d229e043359266 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java |
@@ -7,7 +7,9 @@ package org.chromium.chrome.browser; |
import android.app.ActivityManager; |
import android.content.Context; |
import android.content.Intent; |
+import android.content.pm.ApplicationInfo; |
import android.content.pm.PackageManager; |
+import android.content.pm.PackageManager.NameNotFoundException; |
import android.content.pm.ResolveInfo; |
import android.graphics.Bitmap; |
import android.graphics.BitmapFactory; |
@@ -90,6 +92,9 @@ public class ShortcutHelper { |
// have to update this string. |
private static final String INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT"; |
+ // The activity class used for launching a WebApk. |
+ private static final String WEBAPK_MAIN_ACTIVITY = "org.chromium.webapk.shell_apk.MainActivity"; |
+ |
// These sizes are from the Material spec for icons: |
// https://www.google.com/design/spec/style/icons.html#icons-product-icons |
private static final float MAX_INNER_SIZE_RATIO = 1.25f; |
@@ -178,6 +183,26 @@ public class ShortcutHelper { |
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); |
} |
+ public static void addWebApkShortcut(Context context, String packageName) { |
+ PackageManager pm = context.getPackageManager(); |
+ ApplicationInfo appInfo = null; |
Xi Han
2016/08/19 14:23:23
Move line 188 into the try-catch block.
|
+ try { |
+ appInfo = pm.getApplicationInfo( |
+ packageName, PackageManager.GET_META_DATA); |
+ String shortcutTitle = pm.getApplicationLabel(appInfo).toString(); |
+ Bitmap shortcutIcon = ((BitmapDrawable) pm.getApplicationIcon(packageName)).getBitmap(); |
+ |
+ Bitmap bitmap = createHomeScreenIconFromWebIcon(shortcutIcon); |
+ Intent i = new Intent(); |
+ i.setClassName(packageName, WEBAPK_MAIN_ACTIVITY); |
+ i.addCategory(Intent.CATEGORY_LAUNCHER); |
+ context.sendBroadcast(createAddToHomeIntent("", shortcutTitle, bitmap, i)); |
Yaron
2016/08/18 17:37:39
i think the first param is unused and could be rem
gone
2016/08/18 21:16:01
Weird. Follow up CL?
|
+ } catch (NameNotFoundException e) { |
+ e.printStackTrace(); |
+ } |
+ } |
+ |
+ |
/** |
* Adds home screen shortcut which opens in the browser Activity. |
*/ |