I am trying to implement custom chrome tabs. I am using Google's default library customtabs.
I referred this tutorial for implementing custom chrome tabs. now as suggested in tutorial, I did my coding something like this.
mCustomTabsServiceConnection = new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(
ComponentName componentName,
CustomTabsClient customTabsClient) {
mCustomTabsClient = customTabsClient;
mCustomTabsClient.warmup(0L);
mCustomTabsSession = mCustomTabsClient.newSession(null);
}
@Override
public void onServiceDisconnected(ComponentName name) {
mCustomTabsClient = null;
}
};
CustomTabsClient.bindCustomTabsService(this, "com.android.chrome",
mCustomTabsServiceConnection);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(
mCustomTabsSession).setShowTitle(true);
builder.setToolbarColor(getResources().getColor(R.color.purple_main));
builder.setStartAnimations(getApplicationContext(), R.anim.fadein,
R.anim.fadeout);
builder.setExitAnimations(getApplicationContext(), R.anim.fadein,
R.anim.fadeout);
mCustomTabsIntent = builder.build();
and launching custom tabs.
mCustomTabsIntent.launchUrl(TampleDetails.this,
Uri.parse(temple_website));
Now as you see I have bind custom tabs with chrome's package name, still it asks for choosing between Chrome and UC Browser. and it is obvious UC browser doesn't supports Custom tabs.
So my Question is how to restrict Custom tabs to bind only with Chrome Browser?
any help will be appreciated.
Thank you.
Check this stackoverflow answer: if you set the CustomTabIntent package with the package of your desired browser before launch the url, you can skip the Android dialog browser choice; for me it worked:
/**
* Opens the URL on a Custom Tab
*
* @param activity The host activity.
* @param uri the Uri to be opened.
*/
public static void openCustomTab(Activity activity,
Uri uri) {
// Here is a method that returns the chrome package name
String packageName = CustomTabsHelper.getPackageNameToUse(activity, mUrl);
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
mCustomTabsIntent = builder
.setShowTitle(true)
.build();
builder.setToolbarColor(ContextCompat.getColor(activity, R.color.colorPrimary));
if ( packageName != null ) {
mCustomTabsIntent.intent.setPackage(packageName);
}
mCustomTabsIntent.launchUrl(activity, uri);
}