5

我已经实现了应用链接来处理我域中的所有 url,如下所示

    <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="www.example.com"
                android:scheme="http" />
     </intent-filter> 

但我想在customtabs中打开来自同一域的一些链接。我正在实现这个逻辑来调用 customtabs 中的这些链接

    CustomTabsServiceConnection connection = new CustomTabsServiceConnection() {
        @Override
        public void onCustomTabsServiceConnected(ComponentName componentName, CustomTabsClient client) {
            client.warmup(0L);
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
            builder.setInstantAppsEnabled(false);
            builder.setToolbarColor(context.getResources().getColor(R.color.pure_white));
            builder.setSecondaryToolbarColor(context.getResources().getColor(R.color.pure_white));
            builder.setShowTitle(true);
            CustomTabsIntent customTabsIntent = builder.build();
            customTabsIntent.launchUrl(context,Uri.parse("http://www.example.com/unhandled"));
        }
        @Override
        public void onServiceDisconnected(ComponentName name) {}
    };
    CustomTabsClient.bindCustomTabsService(context, "com.android.chrome", connection);

但是这些链接是由我的 applink 意图捕获的,并且它会循环进行。我错过了什么?任何想法或建议都会很有用。

4

1 回答 1

8

在启动 CustomTabs 的 Intent 上设置包应该强制它打开 Chrome。

CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setPackage("com.android.chrome");
customTabsIntent.launchUrl(
    context,Uri.parse("http://www.example.com/unhandled"));

此外,由于 Chrome 不是唯一支持自定义标签的浏览器,我建议遵循最佳实践,并支持其他浏览器。

于 2017-12-09T18:39:39.673 回答