4

How to load chrome custom tab when multiple browsers installed in the device and...

 2 years ago
source link: https://stackoverflow.com/questions/55804802/how-to-load-chrome-custom-tab-when-multiple-browsers-installed-in-the-device-and/55805637#55805637
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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?

Join Stack Overflow to learn, share knowledge, and build your career.

Asked 2 years, 2 months ago
Viewed 736 times

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

asked Apr 23 '19 at 5:23

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));
answered Apr 23 '19 at 6:40

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

answered May 4 '19 at 9:20

Your Answer

Sign up or log in

Sign up using Google
Sign up using Facebook
Sign up using Email and Password

Post as a guest

Name
Email

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged android google-chrome browser chrome-custom-tabs or ask your own question.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK