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

标签 android android-intent android-manifest android-11

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

相关文章:

android - 如何以编程方式打开 Google Play 商店的 "My account"

android - 从一个 Activity 按下后退按钮会刷新堆栈中的前一个 Activity

android - Android M 中的应用程序崩溃

java - Gradle 任务 assembleDebug 失败,退出代码为 1(运行时异常)

android - 防止 Logcat 删除条目

android - APK部署问题

android-manifest - 如何将我的应用转换为 Android TV 应用?

Java:子类实现了接口(interface),父类却覆盖了接口(interface)的成员?

android - 你如何在广播接收器中接收拨出电话

android - 如何接受市场 Intent ://specific to your application package name