Android deeplink per flavor
Asked Answered
M

2

14

I have multiple deeplink schemes for different app flavors. I have a backend which sends a different scheme per app. If all of them are installed on the same device, all of them will be able to parse the deeplink sent. So when all three are installed and the deeplink for app2 is called. All apps are able to catch it, but only app2 can properly process it in the app and should be the only one able catch it.

Flavors defined in my .gradle file

productFlavors {
    app1{
        applicationId "com.apps.app1"
    }
    app2{
        applicationId "com.apps.app2"
    }
    app3{
        applicationId "com.apps.app3"
    }
}

The intent filter I use to catch the deeplinks in my manifest.

<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:pathPrefix="/"
        android:scheme="app1" />
    <data
        android:pathPrefix="/"
        android:scheme="app2" />
    <data
        android:pathPrefix="/"
        android:scheme="app3" />
</intent-filter>

Is there a way to make a deeplink only catch-able by one flavor?

Mono answered 23/3, 2017 at 9:10 Comment(2)
You can also provide a string resource for android:scheme="@string/scheme" and override it on each flavor, or similarly, using manifest merger placeholders like ${scheme} configurable with gradle.Earthenware
This answer has an exampleDean
C
5

You have to provide each product flavor a manifest file of their own, within which you can specify distinct URI pattern for deep links.

You can refer to Configure Build Variants and Merge Multiple Manifest Files for details about how to achieve that, and more things about building app for product flavor.

Casing answered 23/3, 2017 at 10:20 Comment(0)
R
37

For people visiting this in 2019: You can use manifestPlaceholders per flavor. In your case:

productFlavors {
  app1{
    applicationId "com.apps.app1"
    manifestPlaceholders.scheme = "app1"
  }
  app2{
    applicationId "com.apps.app2"
    manifestPlaceholders.scheme = "app2"
  }
  app3{
    applicationId "com.apps.app3"
    manifestPlaceholders.scheme = "app3"
  }
}

and then use it in your manifest:

<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:pathPrefix="/"
    android:scheme="${scheme}" />

Rodie answered 29/7, 2019 at 13:11 Comment(0)
C
5

You have to provide each product flavor a manifest file of their own, within which you can specify distinct URI pattern for deep links.

You can refer to Configure Build Variants and Merge Multiple Manifest Files for details about how to achieve that, and more things about building app for product flavor.

Casing answered 23/3, 2017 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.