1

I am working on system application handling in my app. I have generated the complete list of all the installed apps in Android device in my app. Now my task is to identify the SYSTEM Apps from that list of application. Or Identify the CURRENT FOREGROUND App is an SYSTEM APP or INSTALLED APP ?

Using below code currently:

PackageManager packageManager = getPackageManager();
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0);
Collections.sort(appList, new ResolveInfo.DisplayNameComparator(packageManager));

List<PackageInfo> packs = packageManager.getInstalledPackages(0); //PackageManager.GET_META_DATA
for(int i=0; i < packs.size(); i++) {
PackageInfo p = packs.get(i);
ApplicationInfo a = p.applicationInfo;
if ((!includeSysApps) && ((a.flags & ApplicationInfo.FLAG_SYSTEM) == 1))
{
continue;
}

apps.add(p.packageName);
Sam-In-TechValens
  • 2,501
  • 4
  • 34
  • 67

1 Answers1

0

below code differs the system apps and installed apps.

List<ApplicationInfo> installedApps = getPackageManager().getInstalledApplications(0);
    for (int i = 0; i < installedApps.size(); i++) {
        if(installedApps.get(i).sourceDir.startsWith("/data/app/")){
        //Non System Apps
        }else{
        //system Apps
        }}
usharani
  • 1
  • 2