Index: chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeShortcutManager.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeShortcutManager.java b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeShortcutManager.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..eaca950f82ef2498405c2a2ac2612d0bc896ee60 |
--- /dev/null |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/webapps/ChromeShortcutManager.java |
@@ -0,0 +1,51 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.chrome.browser.webapps; |
+ |
+import android.annotation.SuppressLint; |
+import android.content.Context; |
+import android.content.Intent; |
+import android.content.pm.PackageManager; |
+import android.content.pm.ResolveInfo; |
+ |
+import org.chromium.chrome.browser.ChromeApplication; |
+import org.chromium.chrome.browser.ShortcutHelper; |
+ |
+import java.util.List; |
+ |
+/** |
+ * This class helps to add a shortcut to the Android Home Screen. It also tells if |
+ * addShortcutToHomeScreen is supported or not. |
+ */ |
+public class ChromeShortcutManager { |
+ private static ChromeShortcutManager sInstance; |
+ |
+ /* Returns the singleton instance of ChromeShortcutManager, creating it if needed. */ |
+ public static ChromeShortcutManager getInstance(Context context) { |
+ if (sInstance == null) { |
+ sInstance = ((ChromeApplication) context.getApplicationContext()) |
+ .createChromeShortcutManager(); |
+ } |
+ return sInstance; |
+ } |
+ |
+ public void addShortcutToHomeScreen(final Context context, final Intent intent) { |
dominickn
2017/02/13 05:18:02
Instead of taking an Intent, can this take the id,
Marti Wong
2017/02/14 02:42:47
Done.
|
+ context.sendBroadcast(intent); |
+ } |
+ |
+ // TODO(crbug.com/635567): Fix this properly. |
+ @SuppressLint("WrongConstant") |
+ public boolean isAddShortcutToHomeScreenSupported(final Context context) { |
dominickn
2017/02/13 05:18:02
Perhaps call this canAddShortcutToHomescreen()
Marti Wong
2017/02/14 02:42:47
Done.
|
+ PackageManager pm = context.getPackageManager(); |
+ Intent i = new Intent(ShortcutHelper.INSTALL_SHORTCUT); |
+ List<ResolveInfo> receivers = |
+ pm.queryBroadcastReceivers(i, PackageManager.GET_INTENT_FILTERS); |
+ return !receivers.isEmpty(); |
+ } |
+ |
+ public boolean canShowAddedToHomescreenToast(final Context context) { |
dominickn
2017/02/13 05:18:02
Maybe call this shouldShowAddedToHomescreenToast()
Marti Wong
2017/02/14 02:42:47
Done.
|
+ return true; |
+ } |
+} |