I want to force the usage of custom tabs in my app. Currently it loops as soon as I try to open the deeplinked URL with my app via the custom tabs.
<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>
This code tries to open the custom tabs but I don't want the deeplink to handle the url again and loop with my app...
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));