首页 > 解决方案 > 强制深层链接在外部打开(chrome 自定义标签)

问题描述

我想强制在我的应用程序中使用自定义选项卡。目前,只要我尝试通过自定义标签打开我的应用程序的深层链接 URL,它就会循环。

<activity
    android:name="com.example.android.UrlActivity"
    android:launchMode="singleTop">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
            android:host="app.example.com"
            android:scheme="http" />
        <data
            android:host="app.example.com"
            android:scheme="https" />

    </intent-filter>
</activity>

此代码尝试打开自定义选项卡,但我不希望深层链接再次处理 url 并与我的应用程序循环...

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
[...]
CustomTabsIntent customTabsIntent = builder.build();

// Get all apps that can handle VIEW intents.
List<ResolveInfo> resolvedActivityList = context.getPackageManager().queryIntentActivities(customTabsIntent.intent, 0);
ArrayList<ResolveInfo> packagesSupportingCustomTabs = new ArrayList<>();
for (ResolveInfo info : resolvedActivityList) {
    Intent serviceIntent = new Intent();
    serviceIntent.setAction(CustomTabsService.ACTION_CUSTOM_TABS_CONNECTION);
    serviceIntent.setPackage(info.activityInfo.packageName);
    // Check if this package also resolves the Custom Tabs service.
    if (context.getPackageManager().resolveService(serviceIntent, 0) != null) {
        // don't use this app
        if (!info.activityInfo.packageName.equals(context.getPackageName()))
            packagesSupportingCustomTabs.add(info);
    }
}
customTabsIntent.intent.putExtra(Intent.EXTRA_INITIAL_INTENTS, packagesSupportingCustomTabs.toArray(new Parcelable[]{}));

customTabsIntent.launchUrl(context, Uri.parse(url));

标签: androiddeep-linkingchrome-custom-tabs

解决方案


推荐阅读