简体   繁体   中英

Android get a list of all installed apps

I have obtained a list of installed app using this code:

public List<ResolveInfo>() {
    PackageManager pm=getPackageManager();
    Intent main=new Intent(Intent.ACTION_MAIN, null);

    main.addCategory(Intent.CATEGORY_LAUNCHER);

    List<ResolveInfo> launchables=pm.queryIntentActivities(main, 0);

}

There is only a problem: it list only apps that has a MAIN activity. How can I get a List of all installed apps? Note that I used this code in a project that need that the List is of ResolveInfo, so please answer only code that returns a List of ResolveInfo.

Have you tried with:

 List<ApplicationInfo> packages = pm
            .getInstalledApplications(PackageManager.GET_META_DATA);

(found here )

Your question doesn't quite make sense; you're making a bit of an unreasonable request. You say you want a list of all installed apps, but you also want a List of ResolveInfo objects. The docs of ResolveInfo describe it as:

Information that is returned from resolving an intent against an IntentFilter.

Apps and IntentFilter s don't correlate one to one. What would you want the ResolveInfo objects to contain? If there's more than one for a package, which one would you want?

PackageManager does include a method getInstalledApplications , but it returns a List of ApplicationInfo objects which is a more appropriate type for this sort of query. Likewise there's a getInstalledPackages method as well that returns a List of PackageInfo objects.

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