Search code examples
androidandroid-manifestandroid-api-30

Different AndroidManifest content depending on Android API Level


Is it possible to include meta-data in my Android Manifest file for only a specific API level?

I want the following line only be considered when the app is built on a phone with Android API >= 30:

    <meta-data android:name="disable_batch_scanning" android:value="true"  />

I tried to set a boolean variable under res/values/bools.xml like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <bool name="isLess31">true</bool>
</resources>

And use it with the tag: android:enabled="@bool/isLess31" Therefore, I also created a values-v31 folder where is set isLess31 to false

But this does not seem to work. Is there another way that disable_batch_scanning is only executed for older Android APIs?


Solution

  • What you should do is this:

    Create file used for default values.

    res/values/bool.xml
    
    <resources>
        <bool name="disable_batch_scanning_variable">true</bool>
    </resources>
    

    And also create one for specific value. This one will be used for APIs equal to 31 and above.

    res/values-v31/bool.xml
    
    <resources>
        <bool name="disable_batch_scanning_variable">false</bool>
    </resources>
    

    In Android Manifest file:

    <meta-data android:name="disable_batch_scanning" android:value="@bool/disable_batch_scanning_variable"  />