Skip to content

Instantly share code, notes, and snippets.

@andreban
Created January 25, 2018 10:10
Show Gist options
  • Save andreban/b06c6736531981d86b1de96b1c8557c6 to your computer and use it in GitHub Desktop.
Save andreban/b06c6736531981d86b1de96b1c8557c6 to your computer and use it in GitHub Desktop.
/**
* 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