关于QUERY_ALL_PACKAGES权限问题

Android11之后,resolveActivity、查询某个APP是否已安装等需要特殊处理。

要么加QUERY_ALL_PACKAGES权限,要么就在清单文件中使用<queries>标签。

由于Google Play的政策:

如果您的应用不需要使用 QUERY_ALL_PACKAGES 权限,请从您的应用清单中移除该权限。如果应用需要此权限,您现在可以在 Play 管理中心内提交声明表单。

您需要提供:

1.对需要此权限的应用核心功能的说明
2.展示需要此权限的应用核心功能的短视频
如需了解您在该表单中将需要回答哪些问题以便做好准备,请参阅这篇帮助中心文章。

自 7 月 12 日起,如果缺少此声明,您将无法提交新应用和应用更新。请您务必在 7 月 12 日之前提交此声明,或者从您的应用清单中移除该权限。从 7 月 12 日起,对于不符合政策要求或未提交此声明表单的应用,我们可能会将其从 Google Play 下架。

感谢您一直以来与我们通力合作,共同努力让 Google Play 成为值得您和用户信赖的可靠平台。

如果用QUERY_ALL_PACKAGES权限,在用户看来,你调用API的时候会出现“XXX”正在查询你安装的应用列表,这样的提示。就会认为你是流氓应用。

因此我们选择使用<queries>标签:

<queries>
        <package android:name="${applicationId}" />

        <!--WhatsApp-->
        <package android:name="com.whatsapp" />
        <!--Facebook-->
        <package android:name="com.facebook.katana" />
        <!--Line客户端-->
        <package android:name="jp.naver.line.android" />
        <!--Twitter-->
        <package android:name="com.twitter.android" />
        <!--WeChat-->
        <package android:name="com.tencent.mm" />
        <!--QQ-->
        <package android:name="com.tencent.mobileqq" />
        <!--instagram-->
        <package android:name="com.instagram.android" />
        <!--Messenger-->
        <package android:name="com.facebook.orca" />

        <!--拍照应用-->
        <intent>
            <action android:name="android.media.action.IMAGE_CAPTURE" />
        </intent>

        <!--Alipay-->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data
                android:host="*"
                android:scheme="alipays" />
        </intent>

        <!--应用商店-->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data
                android:host="*"
                android:scheme="market" />
        </intent>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data
                android:host="play.google.com"
                android:scheme="https" />
        </intent>

        <!--webview 中的 intent-->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data
                android:host="*"
                android:scheme="intent" />
        </intent>
        <!--Line群-->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data
                android:host="ti"
                android:scheme="line" />
        </intent>

    </queries>

这样一来,在使用resolveActivity或者getPackageInfo API的时候就不会出现问题了。