How To Get System Apps And User Installed Apps separately

43 views Asked by At

Im trying to get all apps and separate it to User Installed and System apps using PackageManager.I can get all apps but I can't figure out how to separate them.

This is my current approach:

public List<ApplicationInfo> getApps(String s) {
        List<ApplicationInfo> list = getPackageManager().getInstalledApplications(PackageManager.GET_META_DATA);
        List<ApplicationInfo> userApps = new ArrayList<>();
        List<ApplicationInfo> sysApps = new ArrayList<>();

        for (ApplicationInfo app : list) {

            if (getPackageManager().getLaunchIntentForPackage(app.packageName)==null) {
                
                sysApps.add(app);
            } else {
                userApps.add(app);
            }
        }

        if(s.equals(USER_APPS)){
            return userApps;
        }else {
            return sysApps;
        }
    }

This returns user apps but there are still some pre installed apps like clock, calendar, weather etc, which are not safe to close. Any app that is preinstalled should be considered a system app and not a user app.

I need this in order to automatically force-stop apps.

0

There are 0 answers