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.