[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-27 (世界標準時間)。"],[],[],null,["As you create your app, it's important to consider the other apps on the device\nthat your app needs to interact with. If your app targets\nAndroid 11 (API level 30) or higher, the system makes [some apps visible to your\napp automatically](/training/package-visibility/automatic), but it filters out\nother apps by default. This guide describes how to make those other apps visible\nto your app.\n\nIf your app targets Android 11 or higher and needs to interact\nwith apps other than the ones that are visible automatically, add the\n[`\u003cqueries\u003e`](/guide/topics/manifest/queries-element) element in your app's\nmanifest file. Within the `\u003cqueries\u003e` element, specify the other apps [by\npackage name](#package-name), [by intent signature](#intent-filter-signature),\nor [by provider authority](#provider-authority), as described in the following\nsections.\n\nSpecific package names\n\nIf you know the specific apps that you want to query or interact with, such as\napps that integrate with your app or apps whose services you use, include their\npackage names in a set of [`\u003cpackage\u003e`](/guide/topics/manifest/queries-element)\nelements inside the `\u003cqueries\u003e` element: \n\n```xml\n\u003cmanifest package=\"com.example.game\"\u003e\n \u003cqueries\u003e\n \u003cpackage android:name=\"com.example.store\" /\u003e\n \u003cpackage android:name=\"com.example.services\" /\u003e\n \u003c/queries\u003e\n ...\n\u003c/manifest\u003e\n```\n| **Note:** If you declare a `\u003cpackage\u003e` element in your app's manifest, then the app associated with that package name appears in the results of any query to `PackageManager` that matches a component from that app.\n\nCommunicate with a host app in a library\n\nIf you develop an Android library, you can declare your package visibility needs\nby adding a `\u003cqueries\u003e` element in your [AAR manifest\nfile](/studio/projects/android-library). This `\u003cqueries\u003e` element has the same\nfunctionality as the element that apps can declare in their own manifests.\n\nIf your library involves communication with a host app, such as using a [bound\nservice](/guide/components/bound-services), include a `\u003cpackage\u003e` element that\nspecifies the host app's package name: \n\n```xml\n\u003c!-- Place inside the \u003cqueries\u003e element. --\u003e\n\u003cpackage android:name=PACKAGE_NAME /\u003e\n```\n\nBy including this declaration, you can check if the host app is installed and\ninteract with it, such as by calling\n[`bindService()`](/reference/android/content/Context#bindService(android.content.Intent,%20int,%20java.util.concurrent.Executor,%20android.content.ServiceConnection)).\nThe calling app that uses your library [automatically becomes\nvisible](/training/package-visibility/automatic) to the host app as a result of\nthis interaction.\n\nPackages that match an intent filter signature\n\nYour app might need to query or interact with a set of apps that serve a\nparticular purpose, but you might not know the specific package names to\ninclude. In this situation, you can list\n[intent filter signatures](/training/basics/intents/filters) in your\n`\u003cqueries\u003e` element. Your app can then discover apps that have\nmatching\n[`\u003cintent-filter\u003e`](/guide/topics/manifest/intent-filter-element)\nelements.\n\nThe following code example shows an `\u003cintent\u003e` element that would allow the app\nto see other installed apps that support JPEG image sharing: \n\n```xml\n\u003cmanifest package=\"com.example.game\"\u003e\n \u003cqueries\u003e\n \u003cintent\u003e\n \u003caction android:name=\"android.intent.action.SEND\" /\u003e\n \u003cdata android:mimeType=\"image/jpeg\" /\u003e\n \u003c/intent\u003e\n \u003c/queries\u003e\n ...\n\u003c/manifest\u003e\n```\n\nThe `\u003cintent\u003e` element has a few restrictions:\n\n- You must include exactly one `\u003caction\u003e` element.\n- You cannot use the `path`, `pathPrefix`, `pathPattern`, or `port` attributes in a `\u003cdata\u003e` element. The system behaves as if you set each attribute's value to the generic wildcard character (`*`).\n- You cannot use the `mimeGroup` attribute of a `\u003cdata\u003e` element.\n- Within the `\u003cdata\u003e` elements of a single `\u003cintent\u003e` element, you can use each\n of the following attributes at most once:\n\n - `mimeType`\n - `scheme`\n - `host`\n\n You can distribute these attributes across multiple `\u003cdata\u003e` elements or use\n them in a single `\u003cdata\u003e` element.\n\nThe `\u003cintent\u003e` element supports the generic wildcard character (`*`) as the\nvalue for a few attributes:\n\n- The `name` attribute of the `\u003caction\u003e` element.\n- The subtype of the `mimeType` attribute of a `\u003cdata\u003e` element (`image/*`).\n- The type and subtype of the `mimeType` attribute of a `\u003cdata\u003e` element (`*/*`).\n- The `scheme` attribute of a `\u003cdata\u003e` element.\n- The `host` attribute of a `\u003cdata\u003e` element.\n\nUnless otherwise specified in the previous list, the system doesn't support a\nmix of text and wildcard characters, such as `prefix*`.\n\nPackages that use a specific authority\n\nIf you need to query a [content\nprovider](/guide/topics/providers/content-provider-basics#ContentURIs) but\ndon't know the specific package names, you can declare the provider authority\nin a [`\u003cprovider\u003e`](/guide/topics/manifest/provider-element) element, as shown\nin the following snippet: \n\n```xml\n\u003cmanifest package=\"com.example.suite.enterprise\"\u003e\n \u003cqueries\u003e\n \u003cprovider android:authorities=\"com.example.settings.files\" /\u003e\n \u003c/queries\u003e\n ...\n\u003c/manifest\u003e\n```\n| **Note:** If your `\u003cqueries\u003e` element includes a `\u003cprovider\u003e` element, you might see an editor warning in Android Studio related to the `\u003cprovider\u003e` element. As long as you're using the latest dot release of the Android Gradle plugin, your build is unaffected, so you can disregard the warning. Learn more in the blog post about [Preparing your Gradle build for package visibility in\n| Android 11](https://android-developers.googleblog.com/2020/07/preparing-your-build-for-package-visibility-in-android-11.html).\n\nYou can declare provider authorities in a single `\u003cqueries\u003e` element. Within the\n`\u003cqueries\u003e` element, you can declare one or more `\u003cprovider\u003e` elements. A\n`\u003cprovider\u003e` element can include a single provider authority or a\nsemicolon-delimited list of provider authorities.\n\nAll apps (not recommended)\n\nIn rare cases, your app might need to query or interact with all installed apps\non a device, independent of the components they contain. To allow your app to\nsee all other installed apps, the system provides the\n[`QUERY_ALL_PACKAGES`](/reference/android/Manifest.permission#QUERY_ALL_PACKAGES)\npermission.\n\nSome examples of use cases where the\n`QUERY_ALL_PACKAGES` permission is appropriate to include are:\n\n- Accessibility apps\n- Browsers\n- Device management apps\n- Security apps\n- Antivirus apps\n\nHowever, it's usually possible to fulfill your app's use\ncases by interacting with the set of apps that are [visible automatically](/training/package-visibility/automatic) and by declaring the other apps\nthat your app needs to access in your manifest file. To\nrespect user privacy, your app should request the smallest amount of package\nvisibility necessary in order for your app to work.\n\nThis [policy update from Google\nPlay](https://support.google.com/googleplay/android-developer/answer/10158779)\nprovides guidelines for apps that need the `QUERY_ALL_PACKAGES` permission."]]