简体   繁体   中英

List the all apps in Android

I'm trying to list all apps in android device with queryIntentActivities method but the list doesn't return all the apps, It returns only three of them. Here is my code:

    PackageManager packageManager = getPackageManager();

    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> allApps = packageManager.queryIntentActivities(intent, 0);
    for (ResolveInfo ri : allApps) {
        Log.d("Labels", String.valueOf(ri.loadLabel(packageManager)));
    }

is there anyone now why it returns only 3 applications?

You are most likely trying to do this on Android 11. Make sure you add the <uses-permission android:name"android.permission.QUERY_ALL_PACKAGES"> permission to the AndroidManifest.xml file.

While I haven't tested this aspect of R DP2 yet, it appears that your app now can't find out what other apps are installed, on a general basis. The cited example is queryIntentActivities(), but to make this really work you would need to seriously lobotomize PackageManager. You can whitelist certain packages and certain structures to try to get by this for certain use cases. And, this is where the mysterious QUERY_ALL_PACKAGES permission seen in DP1 comes into play — this permission removes these new restrictions. Given the "look for Google Play to provide guidelines for apps that need this permission" caveat, it is safest to assume that if you try using it, eventually you will be banned from the Play Store by a bot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM