简体   繁体   中英

List of un-installed apps query returning list of installed apps form PackageManager

I am trying to get a list of uninstalled apps from a device using the Pacakge manager. However the code is returning a list of all the installed apps.

// get a list of all installed apps
        List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);



        for(ApplicationInfo unisntalledPackage : packages){


            // itearte hough apps vi acativity manager and get details

            PackageInfo pkginfo=null;
            try {
                pkginfo = pm.getPackageInfo(unisntalledPackage.processName,
                        PackageManager.GET_UNINSTALLED_PACKAGES);
            } catch (NameNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            if (pkginfo !=null && !isSystemPackage(pkginfo)) {

            try{ .....//get info form package object

Any input appreciated.

Using GET_UNINSTALLED_PACKAGES returns "information about all applications (even uninstalled ones) which have data directories." So the code is doing exactly what is expected - you get all the installed packages, and in addition any packages that have been uninstalled but the user chose to leave the data around.

To get just the uninstalled packages, you will have to iterate through the list you have, selecting just the uninstalled ones.

@Zmarties Thanks for the input.

By iterating though the package List and capturing ApplicationInfo objects with TRUE FLAG_IS_DATA_ONLY, the object did not return a integer of 16777216 ( this is the constant returned if is true) we can capture the uninstalled apps;

if(unisntalledPackage.FLAG_IS_DATA_ONLY !=16777216 ){

// then app is unisntalled 

However cannot be sure as have not captured any uninstalled apps with data remaining on my testing device.

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