Sebastian
Sebastian

Reputation: 21

Deep Link opens wrong app (instant app, not installed app)

I'm running into an issue with deep links when having an instant app and an installed app (version). My setup is as follows:

Manifest.xml:

<application>
   <activity
      android:name=".Activity1">
      <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:scheme="https"
            android:host="example.com"
            android:pathPattern="/deeplink/*" />
      </intent-filter>
      ...

Manifest.xml:

<application>
   <activity
      android:name=".Activity2">
      <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:scheme="https"
            android:host="example.com"
            android:pathPattern="/deeplink/*" />
      </intent-filter>
      ...

(Notice that the installed app's manifest defines Activity1, whereas instant app's manifest defines Activity2)

The problem is, that when I open the installed app with a deep link, it opens Activity2 (the instant app's activity) instead of the installed app's activity.

I understand that gradle conducts a manifest merger for dynamic feature modules and the base app that merges all 3 manifests together (base app, installed app, instant app). But I thought android would be smart enough to use the installed app's activity to start the app if it's present on the device.

So my question is: How can you support the same deep link in the installed app AND the instant app at the same time? In other words: If the app is not installed, use instant app's activity (Activity2) to open the deep link, if the app is installed, use the installed app's activity (Activity1) to open the deep link?

Thanks for your help!

Upvotes: 0

Views: 1247

Answers (2)

Sebastian
Sebastian

Reputation: 21

Just in case someone else is having that issue:

It turns out that it has nohting to do with the intent filters. Instead, in your run configuration in Android Studio, in the "Installation Options" you need to select "APK from app bundle" instead of "Default APK" (which is the default selection). Once you do that, the correct dynamic feature is being started.

enter image description here

Upvotes: 1

Ben Weiss
Ben Weiss

Reputation: 17922

In your example intent-filter, the data you use to launch the intent listens to the exact same URL patterns. This is generally discouraged as only one entry in your AndroidManifest will be able to receive this intent from the Android framework.

A module that is instant enabled should not need to differ the installed module, especially if it has the same entry point. Instant or installed is opaque to the user, so they would not expect drastically different behavior.

If you need to differentiate between instant and installed states, you can use PackageManager.isInstantApp() and execute different code depending on the return value.

Upvotes: 0

Related Questions