custom chrome tabs asks for multiple browser to choose

前端 未结 4 1654
轻奢々
轻奢々 2020-12-08 22:14

I am trying to implement custom chrome tabs. I am using Google\'s default library customtabs.

I referred this tutorial for implementing custom chrom

4条回答
  •  情歌与酒
    2020-12-08 23:02

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

提交回复
热议问题