自定义镶边选项卡要求多个浏览器进行选择 [英] custom chrome tabs asks for multiple browser to choose

查看:96
本文介绍了自定义镶边选项卡要求多个浏览器进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现自定义镶边选项卡.我正在使用Google的默认库 customtabs .

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

我引用了教程,用于实现自定义chrome标签.现在,按照教程中的建议,我做了类似的编码.

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

并启动自定义标签.

mCustomTabsIntent.launchUrl(TampleDetails.this,
       Uri.parse(temple_website));

现在,如您所见,我已将自定义标签与chrome的程序包名称绑定在一起,但仍要求在 Chrome UC浏览器之间进行选择.很明显,UC浏览器不支持自定义"选项卡.

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.

所以我的问题是如何限制自定义"标签仅与Chrome浏览器绑定?

So my Question is how to restrict Custom tabs to bind only with Chrome Browser?

任何帮助将不胜感激.

谢谢.

推荐答案

检查这个stackoverflow答案:如果在启动url之前将CustomTabIntent包与所需浏览器的包一起设置,则可以跳过Android对话框浏览器的选择;对我来说,它奏效了:

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

这篇关于自定义镶边选项卡要求多个浏览器进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆