简体   繁体   中英

List of just installed apps

I need to store all the installed apps icons in an array, and names in another array, so I´ve this code:

List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
        int numberApps = apps.size();
        String[] appsNames = new String[numberApps];
        Drawable[] appsIcons = new Drawable[numberApps];


        for(int i=0;i<apps.size();i++) {
            PackageInfo p = apps.get(i);
            String pname = p.packageName;
            String appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
            appsNames[i] = appname;
            Drawable appicon = p.applicationInfo.loadIcon(getPackageManager());
            appsIcons[i] = appicon;

        }

And it works, the problem is that all the apps are displayed, even the system ones, so now i need to change the code for getting just the ones installed or updated by the user. I´ve been searching and I´ve found this and this , but as i´m using a Drawable and string array, and I cannot change that, I don´t know how to make it work. Can someone help me please??

I made a overkill solution for my university some weeks ago: you can have a look at this class on Github.

We were dealing with Android Security Flow, so I do not think it is trivial to get what the app is about but the class suits perfectly your needs.

You would need to invest a bit of time to bind it to your app because it is designed to be asynchronous but it would work. There are probably simpler options though (but who likes it when it's too simple?)

The options you found would work but why are you stuck to an array, can't you create an adapter of it??

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