How to get installed applications in Android and no system apps?

后端 未结 4 423
梦毁少年i
梦毁少年i 2020-12-13 01:05

I want to get all application which appears in the menu screen. But, now I only get the user installed apps or all the application (included the system application).

<
相关标签:
4条回答
  • 2020-12-13 01:21
    final PackageManager pm = getActivity().getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> apps = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
    
    0 讨论(0)
  • 2020-12-13 01:35
    final PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
    

    Using PackageInfo:

    private boolean isSystemPackage(PackageInfo packageInfo) {
        return ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
    }
    

    Using ResolveInfo:

    private boolean isSystemPackage(ResolveInfo resolveInfo) {
        return ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
    }
    

    Using ApplicationInfo:

    private boolean isSystemPackage(ApplicationInfo applicationInfo) {
        return ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
    }
    

    This filters the system package. See this question. Credits: Nelson Ramirez and Kenneth Evans.

    0 讨论(0)
  • 2020-12-13 01:35

    I had the same requirement. Ultimately I added another condition to filter down the app list. I just checked whether the app has 'launcher intent'.

    So, the resultant code looks like...

    PackageManager pm = getPackageManager();
            List<ApplicationInfo> apps = pm.getInstalledApplications(PackageManager.GET_GIDS);
    
            for (ApplicationInfo app : apps) {
                if(pm.getLaunchIntentForPackage(app.packageName) != null) {
                    // apps with launcher intent
                    if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {
                        // updated system apps
    
                    } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
                        // system apps
    
                    } else {
                        // user installed apps
    
                    }
                    appsList.add(app);
                }
    
            }
    
    0 讨论(0)
  • 2020-12-13 01:43

    Below code will give you all the system apps related to Operating System. This will not include Apps like YouTube, Gmail, etc


    try {
        ApplicationInfo ai =  getPackageManager().getApplicationInfo(item.packageName, 0);
        if ((ai.flags & ApplicationInfo.FLAG_SYSTEM ) != 0) {
          if((ai.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP ) == 0) {
            appItem.setSystemApp(true);
            Mylog.v("System Apps " + appItem.getAppName());
          }
        }
      } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
      }
    
    0 讨论(0)
提交回复
热议问题