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



我的应用程序检测某个应用程序是否通过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>

其他一些文件

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

如何使用字符串资源

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

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"]

我也尝试过这个解决方案在我的gradle文件中创建一个字符串资源,但我无法实现。

最新更新