Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

android - custom chrome tabs asks for multiple browser to choose

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...