我已实现 应用链接处理来自我的域的所有 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 中的这些链接
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 意图捕获的,并且循环进行。我错过了什么?任何想法或建议都会很有用。
最佳答案
在启动 CustomTabs 的 Intent 上设置包应该会强制它打开 Chrome。
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.setPackage("com.android.chrome");
customTabsIntent.launchUrl(
context,Uri.parse("http://www.example.com/unhandled"));
此外,由于 Chrome 不是唯一支持自定义标签的浏览器,我建议遵循 best practices ,并支持其他浏览器。
关于deep-linking - 未处理的应用程序链接的自定义选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47576324/