The second Android 11 Developer Preview is now available, test it out and share your feedback.

Package visibility in Android 11

Android 11 changes how apps can query and interact with other installed apps on the same device. If your app targets Android 11, most common interactions don't require changes to your app. In some cases, you might need to add a <queries> element in your app's manifest file so that the system knows which other apps to show to your app.

The <queries> element allows you to describe which other apps your app might need to interact with. You can specify apps by package name or by intent signature within a single <queries> element.

The PackageManager methods that return results about other apps—such as queryIntentActivities()—are filtered based on the calling app's <queries> declaration. Explicit interactions with other apps, such as startService(), also require the target app to match one of the declarations in <queries>.

Most common interactions aren't affected

In many cases, including the following, your app doesn't need to include a <queries> declaration:

  • The target app is your own app.
  • Your activity uses an implicit intent to start an activity.

  • Your app interacts with certain system packages, such as the media provider, that implement core Android functionality.

  • Another app expects a result from your app. For example, if another app makes a request to a content provider in your app, the system allows your app to see that other app.

Query and interact with specific packages

If you know the specific set of apps that you want to query or interact with—such as apps that integrate with your app, or apps whose services you use—include their package names in a set of <package> elements inside the <queries> tag:

<manifest package="com.example.game">
    <queries>
        <package android:name="com.example.store" />
        <package android:name="com.example.services" />
    </queries>
    ...
</manifest>

Query and interact with apps given an intent filter

Your app might need to query or interact with a set of apps that serve a particular purpose, but you might not know the specific package names to include. In this situation, you can list intent filter signatures in your <queries> tag. Your app can then discover apps that have matching <intent-filter> tags.

The following example allows your app to see installed apps that support JPEG image sharing:

<manifest package="com.example.game">
    <queries>
        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="image/jpeg" />
        </intent>
    </queries>
    ...
</manifest>

Note: If you indicate a need to discover a specific app by declaring a <package> element, then you don't need to also declare the <intent> elements that represent the intent actions used in that app.

The reverse case is also true. If your <queries> element includes an <intent> element, then you don't need to also include a <package> element if you know that the package supports the intent that you've defined.

Query and interact with all apps

In rare cases, your app might need to query or interact with all installed apps on a device, independent of the components they contain. An example is an app store like Google Play. To allow your app to see all other installed apps, Android 11 introduces the QUERY_ALL_PACKAGES permission.

Note: In the vast majority of cases, it's possible to fulfill your app's use case by declaring the <queries> tag.

In upcoming versions of the Developer Preview, look for Google Play to provide guidelines for apps that need this permission.

Test the change

To test whether this behavior change has taken effect in your app, complete the following steps:

  1. Install Android Studio 3.6.1 or higher.
  2. Set your app's targetSdkVersion to 'R'.
  3. Don't include the <queries> element in your app's manifest file.
  4. Call getInstalledApplications() or getInstalledPackages(). Both methods should return a filtered list.
  5. See which features of your app aren't working.
  6. Introduce appropriate <queries> entries to fix these features.