我的应用程序检测是否通过 queryIntentActivities
安装了某个应用程序.由于我的应用程序以 api 级别 30 为目标,因此 stopped working因为我错过了一些 list 声明。
在 this example他们直接定义包名。但是我要查询的应用程序对于每个构建变体都不同。所以最好使用字符串资源。然而,这似乎是不可能的。
示例
<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"]
我也试过this solution在我的 gradle 文件中创建一个字符串资源,但我无法让它工作。
关于Android 11 在带有字符串资源的 Android Manifest 中声明包可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67192933/