Get Only Installed Apps in the List ( Not the system apps )
Asked Answered
O

0

6

I was implementing code to show only the user-installed apps (like facebook) and some updated_system_apps (like Gmail,youtube etc.) using the below code. But It is showing some other apps too. So my question is what is the way to remove these types of apps.

My ultimate aim is to show app list just like Google Play Store shows them.

I have read these solutions: Get list of installed android applications

https://stacktips.com/tutorials/android/how-to-get-list-of-installed-apps-in-android

http://theopentutorials.com/tutorials/android/listview/how-to-get-list-of-installed-apps-in-android/

https://www.android-examples.com/get-list-installed-apps-package-name-icons/

https://inducesmile.com/android/android-list-installed-apps-in-device-programmatically/

packageManager = getPackageManager();

List<PackageInfo> packageInfoList = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
List<PackageInfo> installedPackageInfo = new ArrayList<PackageInfo>();

for(PackageInfo pi: packageInfoList){
    if(!isSystemPackage(pi)){
          installedPackageInfo.add(pi);
    }
}
boolean isSystemPackage(PackageInfo pkgInfo){
        if((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)!=0)
            return false;
        else if((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)!=0)
            return true;
        else if((pkgInfo.applicationInfo.flags & ApplicationInfo.FLAG_INSTALLED)!=0)
            return false;
        else
            return true;

    }

Update: I have added the image showing some non-relevant apps.

enter image description here enter image description here

Ocrea answered 8/8, 2019 at 15:45 Comment(2)
I was able to achieve a pretty good list by filtering out apps that do not have a main activity intent via "packageManager.getLaunchIntentForPackage(packageName) != null"Turbellarian
Thnaks Jacob your advice actually workedSkipp

© 2022 - 2024 — McMap. All rights reserved.