【问题标题】:Android 11 declaring package visibility in Android Manifest with string resourceAndroid 11 使用字符串资源在 Android Manifest 中声明包可见性
【发布时间】:2021-07-15 11:26:06
【问题描述】:

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

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>

如何使用字符串资源

【问题讨论】:

  • 您可以像示例中一样直接使用包名称,但会覆盖每个构建的清单文件,因此每个构建都会有正确的查询列表。

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


【解决方案1】:

我用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 文件中创建一个字符串资源,但我无法让它工作。

【讨论】:

  • 知道如何获取像 - com.companyName.* 这样的包吗?可以有多个包具有相同的前缀但不同的后缀。
猜你喜欢
  • 2021-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多