LessThanJake LessThanJake - 9 months ago 64
Android Question

Custom Intent for each app flavor?

Say I have app A and B. App B has multiple build flavors but each one is slightly different and I want to launch a specific flavor from app A.

I have considered using one custom shared intent but I don't want the OS to prompt the user about which version to use to handle the intent if they have multiple versions of B installed.

Is it possible to programatically define unique custom intents for each flavor of an application?


In order to use one shared AndroidManifest between multiple flavors and have unique intents for each I added a manifest placeholder for each flavor in build.gradle

default {
    manifestPlaceholders = [uriPrefix: "myprefix"]
    manifestPlaceholders = [uriPrefix: "otherprefix"]

In AndroidManfest.xml use a manifest placeholder like so in the intent filter:

            <action android:name="com.custom.app.${uriPrefix}.SOME_ACTION" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:scheme="${uriPrefix}" />