[JAVA] The list of installed apps is not displayed in getPackageManager (Android11 ​​/ API level 30)

Until now, you could easily get the installed application information in the terminal by using getPackageManager () # getInstalledPackages (). However, from Android 11 (API level 30), only system application information can be obtained by simply writing the following code.

** Example) Log output of the installed application in the device **

MainActivity.java


PackageManager pm = getApplicationContext().getPackageManager();
        List<PackageInfo> appInfoList = pm.getInstalledPackages(0);
        for(int i =0;i<appInfoList.size();i++){
            Log.d("MainActivity",appInfoList.get(i).applicationInfo.loadLabel(pm).toString());
        }

What was wrong

Since Android 11 (API level 30), security has become stricter, and access to external packages must be specified in Manifest.

solution

I write the permission description in AndroidManifest.xml.

AndroidManifest.xml


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

… It seems to be a deprecated method because it allows everything. Originally, it may be the correct way to enclose it in <queries> and specify it individually.

reference

Accessing packages on Android 11-Android Developers

Recommended Posts

The list of installed apps is not displayed in getPackageManager (Android11 ​​/ API level 30)
When the project is not displayed in eclipse
[Error] The app is not displayed in the production environment
[Rails] About the error that the image is not displayed in the production environment
Image is not displayed in production environment
[Cloud9] Yay! You ’re on Rails! Is not displayed in the rails tutorial
Is it mainstream not to write the closing tag of <P> tag in Javadoc?
ActiveSupport underscore is not the inverse of camelize
The devise error message is not displayed properly.
The story of tuning android apps with libGDX
GoogleMap is not displayed until the browser is reloaded
The public key for jenkins-2.249.1-1.1.noarch.rpm is not installed
[Java] Something is displayed as "-0.0" in the output
Ebean.update () is not executed in the inherited model.
How to use UsageStatsManager in Android Studio (How to check the startup time of other apps)
How to set the log level to be displayed in the release version of orhanobut / logger
[Android Studio] About the matter that the design view is not displayed when using TextClock
In Time.strptime,% j (total date of the year) is
I saw the list view of Android development collectively
<Android> Change the background color of the List row of ListView
The objects in the List were references, right? Confirmation of
[Android] Variable of Data Binding is written in camelCase
[Android] Hook the tap of the anchor link in WebViewClient
Changing the debug build signature of the android app to the release signature is useful in many ways.
When rewriting the CMD of docker image of Pod in the manifest of k8s, command is not good
Even if I write the setting of STRICT_QUOTE_ESCAPING in CATALINA_OPTS in tomcat8.5, it is not reflected.
Determine that the value is a multiple of 〇 in Ruby
What is the representation of domain knowledge in the [DDD] model?
Error in production environment (The asset "~" is not present in the asset pipeline.)
The idea of cutting off when the error is not resolved
When [command not found: composer] is displayed when [composer install] is displayed in Laravel
[Rails] When the layout change of devise is not reflected
A program that counts the number of words in a List
The selected JRE does not support the current compliance level of 15
[Android] Try to display the effect on the touched part of the screen, which is common in games.
[Note] What to do if bundle install in Chapter 3 of the rails tutorial is not possible