Android 上的软件包可见性过滤
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
如果应用以 Android 11(API 级别 30)或更高版本为目标平台,并查询与设备上已安装的其他应用相关的信息,则系统在默认情况下会过滤此信息。此过滤行为意味着您的应用无法检测设备上安装的所有应用,这有助于最大限度地减少您的应用可以访问但在执行其用例时不需要的潜在敏感信息。
此外,过滤后的软件包可见性可帮助 Google Play 等应用商店评估应用为用户提供的隐私权和安全性。例如,Google Play 会将已安装应用的列表视为个人和敏感用户数据。
有限的应用可见性会影响提供其他应用相关信息的方法的返回结果,例如 queryIntentActivities()
、getPackageInfo()
和 getInstalledApplications()
。有限的可见性还会影响与其他应用的显式交互,例如启动另一个应用的服务。
部分软件包是自动可见的。您的应用始终可以在查询其他已安装的应用时检测这些软件包。如需查看其他软件包,请使用 <queries>
元素声明您的应用需要提高软件包可见性。用例页面提供了有关如何选择性地扩展软件包可见性的示例。其中介绍的工作流可让您在保护用户隐私的同时执行常见的应用交互场景。
在极少数情况下,如果遇到 <queries>
元素无法提供适当的软件包可见性,您还可以使用 QUERY_ALL_PACKAGES
权限。如果您在 Google Play 上发布应用,那么应用使用此权限需要获得批准。
介绍测试软件包可见性行为页面提供了有关如何在应用依赖与其他应用交互的情况下根据软件包可见性测试行为变更的建议。
其他资源
如需详细了解 Android 中的软件包可见性,请查看以下资料:
博文
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-21。
[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Package visibility filtering on Android\n\nWhen an app targets Android 11 (API level 30) or higher and queries for\ninformation about the other apps that are installed on a device, the system\nfilters this information by default. This filtering behavior means that your app\ncan't detect all the apps installed on a device, which helps minimize the\npotentially sensitive information that your app can access but doesn't need\nto fulfill its use cases.\n\nAlso, filtered package visibility helps app\nstores like Google Play assess the privacy and security that your app provides\nfor users. For example, Google Play considers the list of installed apps to be\n[personal and sensitive user\ndata](https://support.google.com/googleplay/android-developer/answer/10144311#zippy=%2Cexamples-of-common-violations).\n\nLimited app visibility affects the results returned by methods that give\ninformation about other apps, such as\n[`queryIntentActivities()`](/reference/android/content/pm/PackageManager#queryIntentActivities(android.content.Intent,%20int)),\n[`getPackageInfo()`](/reference/android/content/pm/PackageManager#getPackageInfo(java.lang.String,%20int)),\nand\n[`getInstalledApplications()`](/reference/android/content/pm/PackageManager#getInstalledApplications(int)).\nThe limited visibility also affects explicit interactions with other apps, such\nas starting another app's service.\n\nSome packages are [visible\nautomatically](/training/package-visibility/automatic). Your app can always\ndetect these packages in its queries for other installed apps. To view other\npackages, [declare your app's need for increased package\nvisibility](/training/package-visibility/declaring) using the\n[`\u003cqueries\u003e`](/guide/topics/manifest/queries-element) element. The [use\ncases](/training/package-visibility/use-cases) page provides examples of how you\ncan selectively expand package visibility. The workflows described there allow\nyou to fulfill common app interaction scenarios while protecting user privacy.\n\nIn the rare cases where the `\u003cqueries\u003e` element doesn't provide adequate package\nvisibility, you can use the `QUERY_ALL_PACKAGES` permission. If you publish your\napp on Google Play, your app's use of this permission is\n[subject to approval](https://support.google.com/googleplay/android-developer/answer/10158779).\n\nThe page about\n[testing package visibility behavior](/training/package-visibility/testing)\noffers suggestions for how to test behavior changes based on package visibility\nwhen your app relies on interactions with other apps.\n\nAdditional resources\n--------------------\n\nTo learn more about package visibility on Android, view the following materials:\n\n### Blog posts\n\n- [Package visibility in\n Android 11](https://medium.com/androiddevelopers/package-visibility-in-android-11-cc857f221cd9), available on Medium."]]