Faldu Jaldeep
Faldu Jaldeep

Reputation: 595

How to load chrome custom tab when multiple browsers installed in the device and user has set different browser as default instead of chrome browser?

I am developing one android application in that i need to load all the web URL into chrome custom tab but i am facing one issue when user install multiple browser into their device and they set default browser as different instead of chrome browser in this case chrome tab is not getting open.

I am following this document and sample. https://developer.chrome.com/multidevice/android/customtabs https://github.com/GoogleChrome/custom-tabs-client

Upvotes: 2

Views: 2026

Answers (2)

Izhan Ali
Izhan Ali

Reputation: 577

Try this

public static void CustomTab(Activity activity,
                             Uri uri) {
// It 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);
}

If user has installed chrome it will open directly

Upvotes: 0

Shevchyk Vitalii
Shevchyk Vitalii

Reputation: 68

You can add the Google Chrome package to the customTabsIntent:

    CustomTabsIntent tabsIntent = new CustomTabsIntent.Builder().build();
    tabsIntent.intent.setPackage("com.android.chrome");
    tabsIntent.launchUrl(context, Uri.parse(YOUR_URL));

Upvotes: 1

Related Questions