Created
January 25, 2018 10:10
-
-
Save andreban/b06c6736531981d86b1de96b1c8557c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a list of packages that support Custom Tabs. | |
*/ | |
public static ArrayList getCustomTabsPackages(Context context) { | |
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 resolvedActivityList = pm.queryIntentActivities(activityIntent, 0); | |
ArrayList packagesSupportingCustomTabs = new ArrayList<>(); | |
for (ResolveInfo info : resolvedActivityList) { | |
Intent serviceIntent = new Intent(); | |
serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION); | |
serviceIntent.setPackage(info.activityInfo.packageName); | |
// Check if this package also resolves the Custom Tabs service. | |
if (pm.resolveService(serviceIntent, 0) != null) { | |
packagesSupportingCustomTabs.add(info); | |
} | |
} | |
return packagesSupportingCustomTabs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment