Index: shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java |
diff --git a/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java b/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java |
index 00af1e2189019aeabbcfcc4d498e22d09a2a073c..30cb119e3cf5d90445c07ed863c9316bdea00aa8 100644 |
--- a/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java |
+++ b/shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java |
@@ -19,6 +19,7 @@ import android.content.Intent; |
import android.content.IntentFilter; |
import android.content.pm.PackageManager; |
import android.content.pm.ResolveInfo; |
+import android.graphics.Color; |
import android.net.Uri; |
import android.text.TextUtils; |
import android.util.Log; |
@@ -60,9 +61,14 @@ public class CustomTabsHelper { |
* @param context {@link Context} to use for accessing {@link PackageManager}. |
Ian Wen
2016/03/16 01:35:31
Where is the javadoc for the second parameter?
BigBossZhiling
2016/03/18 00:59:08
Done.
|
* @return The package name recommended to use for connecting to custom tabs related components. |
*/ |
- public static String getPackageNameToUse(Context context) { |
+ public static String getPackageNameToUse(Context context, |
+ List<String> packagesSupportingCustomTabs) { |
if (sPackageNameToUse != null) return sPackageNameToUse; |
+ if (packagesSupportingCustomTabs == null) { |
+ packagesSupportingCustomTabs = getAllPackagesSupportingCustomTabs(context); |
+ } |
+ |
PackageManager pm = context.getPackageManager(); |
// Get default VIEW intent handler. |
Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); |
@@ -72,18 +78,6 @@ public class CustomTabsHelper { |
defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo.packageName; |
} |
- // Get all apps that can handle VIEW intents. |
- List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); |
- List<String> packagesSupportingCustomTabs = new ArrayList<>(); |
- for (ResolveInfo info : resolvedActivityList) { |
- Intent serviceIntent = new Intent(); |
- serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); |
- serviceIntent.setPackage(info.activityInfo.packageName); |
- if (pm.resolveService(serviceIntent, 0) != null) { |
- packagesSupportingCustomTabs.add(info.activityInfo.packageName); |
- } |
- } |
- |
// Now packagesSupportingCustomTabs contains all apps that can handle both VIEW intents |
// and service calls. |
if (packagesSupportingCustomTabs.isEmpty()) { |
@@ -107,6 +101,13 @@ public class CustomTabsHelper { |
} |
/** |
+ * See getPackageNameToUse(Context, List<String). |
Ian Wen
2016/03/16 01:35:31
use @see, which is standard way in javadoc.
BigBossZhiling
2016/03/18 00:59:08
Done.
|
+ */ |
+ public static String getPackageNameToUse(Context context) { |
+ return getPackageNameToUse(context, null); |
Ian Wen
2016/03/16 01:35:31
Why can't you directly call getAllPackages......()
BigBossZhiling
2016/03/18 00:59:07
Done.
|
+ } |
+ |
+ /** |
* Used to check whether there is a specialized handler for a given intent. |
* @param intent The intent to check with. |
* @return Whether there is a specialized handler for the given intent. |
@@ -139,4 +140,27 @@ public class CustomTabsHelper { |
public static String[] getPackages() { |
return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL_PACKAGE}; |
} |
+ |
+ /** |
+ * Get all apps that support custom tabs. |
Ian Wen
2016/03/16 01:35:31
If it is a public method, javadocs should be writt
BigBossZhiling
2016/03/18 00:59:08
Done.
|
+ * @param context |
+ * @return |
+ */ |
+ public static ArrayList<String> getAllPackagesSupportingCustomTabs(Context context) { |
Ian Wen
2016/03/16 01:35:31
1. I would make it a private method.
2. I would re
BigBossZhiling
2016/03/18 00:59:08
I think probably it can't be a private method beca
Ian Wen
2016/03/21 18:46:28
Why not use the function in #140?
I would put the
|
+ PackageManager pm = context.getPackageManager(); |
+ // Get default VIEW intent handler. |
+ Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); |
+ // Get all apps that can handle VIEW intents. |
+ List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); |
+ ArrayList<String> packagesSupportingCustomTabs = new ArrayList<>(); |
+ for (ResolveInfo info : resolvedActivityList) { |
+ Intent serviceIntent = new Intent(); |
+ serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); |
+ serviceIntent.setPackage(info.activityInfo.packageName); |
+ if (pm.resolveService(serviceIntent, 0) != null) { |
+ packagesSupportingCustomTabs.add(info.activityInfo.packageName); |
+ } |
+ } |
+ return packagesSupportingCustomTabs; |
+ } |
} |