dancingbush
dancingbush

Reputation: 2281

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.

Upvotes: 1

Views: 638

Answers (2)

dancingbush
dancingbush

Reputation: 2281

@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.

Upvotes: 1

zmarties
zmarties

Reputation: 4869

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.

Upvotes: 2

Related Questions