Android 11 adaptation package visibility

Android 11 package visibility adaptation

1, Package visibility description

If the application takes Android 11 (API level 30) or higher as the target platform, by default, the system will automatically make some applications visible to your application, but hide other applications.
By making some applications invisible by default, the system can know which other applications should be displayed to the application, which helps to encourage the principle of minimum permission.

be careful:

  1. If your application targets Android 10 (API level 29) or lower, all applications will be automatically visible to your application.
  2. Even if your application targets Android 11 (API level 30) or higher, specific scenarios will not be affected.

1. Specific scenarios not affected

  • Some system software packages that implement Android core functions, such as media providers.
  • Use the startActivityForResult() method to start a page of another application.
  • Applications accessed through the Content Provider.
  • Any application that has a Content Provider and has been granted URI permission to access the Content Provider.
  • You can use implicit or explicit intent to start the activity of another application, whether or not the application is visible to your application.

2. List of affected methods

    // Retrieves all activities that can be performed for a given intent
    PackageManager.queryIntentActivities(intent, flag)
    
	// Retrieves all services that can match a given intent
    PackageManager.queryIntentServices(intent, flag)
        
    // Retrieves all receivers that can handle a given intended broadcast
    PackageManager.queryBroadcastReceivers(intent, flag)
        
    // Querying a Content Provider 
    PackageManager.queryContentProviders(processName, uid, flag)

    // Gets a list of all packages installed for the current user.
    PackageManager.getInstalledPackages(flag)

	// Get installed applications
	PackageManager.getInstalledApplications(flag)
    

2, Package visibility configuration

1. Check whether there is a browser available, for example, you need to open an external browser

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" />
        </intent>
    </queries>
</manifest>

2. Check whether the device can open the given file. If necessary, open pdf and zip

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data android:mimeType="*/*" />
        </intent>
    </queries>
</manifest>

3. Create custom sharing forms, such as sharing pictures and files

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="*/*" />
        </intent>
    </queries>
</manifest>

4. Display user-defined text selection operations, such as selecting a paragraph of text to copy and paste

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <intent>
            <action android:name="android.intent.action.PROCESS_TEXT" />
            <data android:mimeType="text/plain" />
        </intent>
    </queries>
</manifest>

5. Connect to text to speech engine

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <intent>
            <action android:name="android.intent.action.TTS_SERVICE" />
        </intent>
    </queries>
</manifest>

6. Connect to speech recognition service

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <intent>
            <action android:name="android.speech.RecognitionService" />
        </intent>
    </queries>
</manifest>

7. Display the custom data line of the contact

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <!-- Allows the app to read the "contacts.xml" file from the other apps. -->
        <intent>
            <action android:name="android.accounts.AccountAuthenticator" />
        </intent>
        <!-- Allows the app to load an icon corresponding to the custom MIME type. -->
        <intent>
            <action android:name="android.intent.action.VIEW" />
            <data
                android:host="com.android.contacts"
                android:mimeType="vnd.android.cursor.item/*"
                android:scheme="content" />
        </intent>
    </queries>
</manifest>

8. Connect to media browser service

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <intent>
            <action android:name="android.media.browse.MediaBrowserService" />
        </intent>
    </queries>
</manifest>

9. configuration visit to WeChat, Alipay, QQ, micro-blog

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <queries>
        <!--WeChat-->
        <package android:name="com.tencent.mm" />

        <!--Alipay-->
        <package android:name="com.eg.android.AlipayGphone" />
        <package android:name="hk.alipay.wallet" />

        <!--QQ-->
        <package android:name="com.tencent.qqlite" />
        <package android:name="com.tencent.mobileqq" />

        <!--Sina Weibo-->
        <package android:name="com.sina.weibo" />
    </queries>
</manifest>

10. Configure, query and interact with all applications (the above may not be configured, but gp will strictly review)

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

Github source code attached:

AndroidManifest.xml

Keywords: Android

Added by Mutley on Sat, 25 Dec 2021 07:18:35 +0200