在 Android 上篩選套件瀏覽權限
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
根據預設,如果指定 Android 11 (API 級別 30) 以上版本的應用程式要查詢裝置上其他已安裝應用程式的資訊,系統會篩選這類資訊。這種篩選行為意味著應用程式無法偵測裝置上安裝的所有應用程式,這麼做能有效減少應用程式可存取但執行用途時不需要的潛在機密資訊。
此外,經過篩選的套件瀏覽權限也有助於如 Google Play 這類應用程式商店評估應用程式提供給使用者的隱私權與安全性。舉例來說,Google Play 會將已安裝應用程式的清單視為個人和機密的使用者資料。
有限的應用程式瀏覽權限會影響提供其他應用程式相關資訊的方法所傳回的結果,例如 queryIntentActivities()
、getPackageInfo()
和 getInstalledApplications()
。此外,有限的瀏覽權限也會影響與其他應用程式的明確互動,例如啟動其他應用程式的服務。
部分套件會自動授予瀏覽權限。您的應用程式隨時可以在對其他已安裝應用程式的查詢中偵測這些套件。如要查看其他套件,請使用 <queries>
元素宣告應用程式需要提高套件瀏覽權限。用途頁面會提供範例,說明如何選擇性提高套件瀏覽權限。該頁面所述的工作流程可讓您在實現常見應用程式互動情境的同時,保護使用者隱私。
在極少數情況下,當 <queries>
元素無法提供適當的套件瀏覽權限,您可以使用 QUERY_ALL_PACKAGES
權限。如果您在 Google Play 上發布應用程式,則應用程式必須獲得核准才能使用這項權限。
如果應用程式需要與其他應用程式互動,請參閱「測試套件瀏覽權限行為」頁面中的建議,瞭解如何根據套件瀏覽權限測試行為異動。
其他資源
如要進一步瞭解 Android 的套件瀏覽權限,請參閱下列資源:
網誌文章
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間: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."]]