Android 11使用字符串资源在Android清单中声明包可见性

Android 11使用字符串资源在Android清单中声明包可见性,android,android-intent,android-manifest,android-11,Android,Android Intent,Android Manifest,Android 11,我的应用程序通过queryIntentActivities检测是否安装了某个应用程序。由于我的应用程序以api级别30为目标,这是因为我缺少一些清单声明 在中,它们直接定义包名。但我想查询的应用程序对于每个构建变量都不同。因此,最好使用字符串资源。然而,这似乎是不可能的 示例 <manifest package="com.example.game"> <queries> <package android:name=&quo

我的应用程序通过
queryIntentActivities
检测是否安装了某个应用程序。由于我的应用程序以api级别30为目标,这是因为我缺少一些清单声明

在中,它们直接定义包名。但我想查询的应用程序对于每个构建变量都不同。因此,最好使用字符串资源。然而,这似乎是不可能的

示例

<manifest package="com.example.game">
    <queries>
        <package android:name="com.example.store" />
        <package android:name="com.example.services" />
    </queries>
    ...
</manifest>
<manifest package="com.example.game">
    <queries>
        <package android:name="@string/store_app" />
        <package android:name="@string/services_app" />
    </queries>
    ...
</manifest>
manifestPlaceholders = [store_app: "com.example.store"]

...
我想要什么

<manifest package="com.example.game">
    <queries>
        <package android:name="com.example.store" />
        <package android:name="com.example.services" />
    </queries>
    ...
</manifest>
<manifest package="com.example.game">
    <queries>
        <package android:name="@string/store_app" />
        <package android:name="@string/services_app" />
    </queries>
    ...
</manifest>
manifestPlaceholders = [store_app: "com.example.store"]

...
其他文件

com.example.store
com.example.services
如何使用字符串资源

我用解决了它,因为我想要一个AndroidManifest。此解决方案的唯一缺点是,我在代码中也使用了应用程序包名称,因此我需要在字符串资源文件中再次定义它

AndroidManifest

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

我还尝试在我的gradle文件中创建字符串资源,但无法使其正常工作。

您可以像示例中那样直接使用包名,但会覆盖每个生成的清单文件,以便每个生成都有正确的查询列表。