Search code examples
androidandroid-intentandroid-manifestandroid-11

Android 11 declaring package visibility in Android Manifest with string resource


My app detects if a certain app is installed via queryIntentActivities. Since my app targets api level 30 this stopped working because I was missing some manifest declarations.

In this example they define the package name directly. But the apps I want to query for differ for each build variant. So it would be better to use a string resource. However this doesn't seem possible.

Example

<manifest package="com.example.game">
    <queries>
        <package android:name="com.example.store" />
        <package android:name="com.example.services" />
    </queries>
    ...
</manifest>

What I would like

<manifest package="com.example.game">
    <queries>
        <package android:name="@string/store_app" />
        <package android:name="@string/services_app" />
    </queries>
    ...
</manifest>

Some other file

<string name="store_app">com.example.store</string>
<string name="services_app">com.example.services</string>

How to use a string resource


Solution

  • I solved it with manifestPlaceholders because I wanted to have a single AndroidManifest. The only downside to this solution is that I also use the app package names in my code and therefore I need to define it once more in a string resource file.

    AndroidManifest

    <manifest package="com.example.game">
        <queries>
            <package android:name="${store_app}" />
            <package android:name="${services_app}" />
        </queries>
        ...
    </manifest>
    

    build.gradle

    manifestPlaceholders = [store_app: "com.example.store"]
    

    I also tried this solution to create a string resource in my gradle file, but I couldn't get that to work.