1

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));
Sebastian Schneider
  • 4,896
  • 3
  • 20
  • 47
  • Hello, You have to do it programatically, like, You can move to home page when your URL loaded in browser or any part. Once your `UrlActivity` loaded, then you can do with this, https://inducesmile.com/android-programming/how-to-programmatically-select-tab-in-android-tablayout/ – IamVariable Dec 02 '19 at 15:19
  • @MuthuS I didn't use Tabs as you might now it, I use the Chome Custom Tabs https://developer.chrome.com/multidevice/android/customtabs – Sebastian Schneider Dec 02 '19 at 15:37

0 Answers0