Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: shared/src/main/java/org/chromium/customtabsclient/shared/CustomTabsHelper.java

Issue 2961203002: Support library changes to allow a callback notifying the selection of default items for Browser Ac… (Closed)
Patch Set: Update based on Yusuf's comments. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 Google Inc. All Rights Reserved. 1 // Copyright 2015 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package org.chromium.customtabsclient.shared; 15 package org.chromium.customtabsclient.shared;
16 16
17 import android.content.Context; 17 import android.content.Context;
18 import android.content.Intent; 18 import android.content.Intent;
19 import android.content.IntentFilter; 19 import android.content.IntentFilter;
20 import android.content.pm.PackageManager; 20 import android.content.pm.PackageManager;
21 import android.content.pm.ResolveInfo; 21 import android.content.pm.ResolveInfo;
22 import android.net.Uri; 22 import android.net.Uri;
23 import android.support.customtabs.CustomTabsClient;
23 import android.text.TextUtils; 24 import android.text.TextUtils;
24 import android.util.Log; 25 import android.util.Log;
25 26
26 import java.util.ArrayList; 27 import java.util.ArrayList;
27 import java.util.List; 28 import java.util.List;
28 29
29 /** 30 /**
30 * Helper class for Custom Tabs. 31 * Helper class for Custom Tabs.
31 */ 32 */
32 public class CustomTabsHelper { 33 public class CustomTabsHelper {
(...skipping 26 matching lines...) Expand all
59 * 60 *
60 * @param context {@link Context} to use for accessing {@link PackageManager }. 61 * @param context {@link Context} to use for accessing {@link PackageManager }.
61 * @return The package name recommended to use for connecting to custom tabs related components. 62 * @return The package name recommended to use for connecting to custom tabs related components.
62 */ 63 */
63 public static String getPackageNameToUse(Context context) { 64 public static String getPackageNameToUse(Context context) {
64 if (sPackageNameToUse != null) return sPackageNameToUse; 65 if (sPackageNameToUse != null) return sPackageNameToUse;
65 66
66 PackageManager pm = context.getPackageManager(); 67 PackageManager pm = context.getPackageManager();
67 // Get default VIEW intent handler. 68 // Get default VIEW intent handler.
68 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /www.example.com")); 69 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /www.example.com"));
69 ResolveInfo defaultViewHandlerInfo = pm.resolveActivity(activityIntent, 0); 70 ResolveInfo defaultViewHandlerInfo = CustomTabsClient.getDefaultHandlerF orIntent(pm, activityIntent);
70 String defaultViewHandlerPackageName = null; 71 String defaultViewHandlerPackageName = null;
71 if (defaultViewHandlerInfo != null) { 72 if (defaultViewHandlerInfo != null) {
72 defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo. packageName; 73 defaultViewHandlerPackageName = defaultViewHandlerInfo.activityInfo. packageName;
73 } 74 }
74 75
75 // Get all apps that can handle VIEW intents. 76 // Get all apps that can handle VIEW intents.
76 List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activi tyIntent, 0); 77 List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activi tyIntent, 0);
77 List<String> packagesSupportingCustomTabs = new ArrayList<>(); 78 List<String> packagesSupportingCustomTabs = new ArrayList<>();
78 for (ResolveInfo info : resolvedActivityList) { 79 for (ResolveInfo info : resolvedActivityList) {
79 Intent serviceIntent = new Intent(); 80 Intent serviceIntent = new Intent();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 return false; 134 return false;
134 } 135 }
135 136
136 /** 137 /**
137 * @return All possible chrome package names that provide custom tabs featur e. 138 * @return All possible chrome package names that provide custom tabs featur e.
138 */ 139 */
139 public static String[] getPackages() { 140 public static String[] getPackages() {
140 return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL _PACKAGE}; 141 return new String[]{"", STABLE_PACKAGE, BETA_PACKAGE, DEV_PACKAGE, LOCAL _PACKAGE};
141 } 142 }
142 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698