Chrome custom tabs and intent-filter
You can use setPackage
:
String PACKAGE_NAME = "com.android.chrome";
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
customTabsIntent.intent.setData(uri);
PackageManager packageManager = getPackageManager();
List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(customTabsIntent.intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resolveInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
if (TextUtils.equals(packageName, PACKAGE_NAME))
customTabsIntent.intent.setPackage(PACKAGE_NAME);
}
customTabsIntent.launchUrl(this, uri);
I have used @Mattia Maestrini's Answer, but i think some might be we have to change
I have already installed latest Chrome (Updated August 8, 2016) in my Nexus 5 (6.0.1)
but I am not getting Chrome Package "com.android.chrome" into resolveInfoList, I have to do changes, then it is working fine on my phone
packageManager.queryIntentActivities(customTabsIntent.intent, PackageManager.MATCH_DEFAULT_ONLY);
above query does not giving me package name of Chrome
String PACKAGE_NAME = "com.android.chrome";
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
customTabsIntent.intent.setData(Uri.parse(url));
PackageManager packageManager = getPackageManager();
List<ApplicationInfo> resolveInfoList = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : resolveInfoList) {
String packageName = applicationInfo.packageName;
if (TextUtils.equals(packageName, PACKAGE_NAME)) {
customTabsIntent.intent.setPackage(PACKAGE_NAME);
break;
}
}
customTabsIntent.launchUrl(this, Uri.parse(url));
I have tested above code and it is working fine on my phone