Package visibility for Android11

Our applications often encounter interaction with other applications, such as login function, we may want to use wechat login or QQ login, and sharing, we first judge whether wechat is installed, and then decide whether to display the sharing icon of wechat and so on. One of our requirements here is to find out if the relevant packages have been installed.

But in Android11, with the exception of the default apps, we can’t directly check whether the package has been installed or not. In other words, we have installed an app, But our calls to getInstalledApplications() or getInstalledPackages() may not return this package name. This is the concept of package visibility introduced in Android11.

Damn, why did you introduce package visibility in Android11?

Here Goole gives two reasons:

  1. Encourage the principle of minimum permissions and apply for package names that need to interact with those applications.
  2. Help app stores like Google Play assess privacy and security.

How do we find out if a package is installed on Android11?

When creating an application, we need to consider the installed applications that our application intends to interact with on the device, and then in manifest, declare the package names with which we will interact by using nodes.

How does Android make packages visible

So let’s talk a little bit more about how do we make packages visible

  1. Install Android Studio 3.6.1 or later.

  2. Upgrade Gradle for Android to version 3.6.0 or later

    "Com. Android. Tools. Build: gradle: 3.6.0"
    Copy the code
  3. Make sure the application’s targetSdkVersion is set to 30

  4. In Manefist, use declarations that our application expects to interact with those applications.

<queries>
	<package android:name="com.facebook.katana" />
	<package android:name="com.tencent.mm" />
</queries>
Copy the code
  1. Call getInstalledApplications() or getInstalledPackages() to see the name of the application package they interact with.

For an example, see github.com/wfeii/Andro…

Other problems

Question 1: PackageManager. QueryIntentActivities () interface in Android11 available?

In Android11, you can use this interface. To function properly, we still need to declare it in manefist. The format is as follows:

<queries>
	<intent>
		<action android:name="android.intent.action.SEND" />
		<data android:mimeType="image/jpeg" />
	</intent>
</queries>
Copy the code

Question 2: What about getting all the applications in the device? For example, my application is anti-virus software, and I need to scan all the software.

The system provides the permission to query all applications. You only need to make the following statement:

<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>
Copy the code

The resources

Developer.android.com/about/versi…

Developer.android.com/training/ba…

Limited to personal level, any mistakes please point out, we learn and progress together!

Scan the public account to see more content.