android - 强制深层链接在外部打开(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));
解决方案
推荐阅读
- node.js - Angular 7 HttpClient get - 你可以访问和处理返回对象吗?
- openscad - how to import an image into openjscad
- ios - Can not add iOS bundle identifier
- ruby-on-rails - build step 0 "gcr.io/google-appengine/exec-wrapper:latest" failed: exit status 1
- java - How to check if current phones date is today or not
- excel-formula - 如何让 VLookup 为不在 Excel 2010 列表中的条目返回零?
- python - 如何从具有特定度数的节点创建 NetworkX 子图?
- javascript - 对类使用泛型类型
- azure-devops - Visual Studio Teams API giving 203 for 1 company
- sql - SQLITE3 查询 COUNT 和 ORDER BY