How to load chrome custom tab when multiple browsers installed in the device and...
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.
Join Stack Overflow to learn, share knowledge, and build your career.
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
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));
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
Your Answer
Post as a guest
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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK