androidmdmsamsung-knox

How to determine a list of Android apps that are in the app drawer


I'm using the Package Manager class to get a list of all installed applications. I tried using the following flags to determine what was a "user app" vs a "system app":

ApplicationInfo.FLAG_SYSTEM
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP

This worked, but not in the exact way I wanted. I want to be able to filter a list of all apps to determine: Is this app visible in the app drawer?

I don't want to interact with the low-level system apps, as that might cause some undesirable side effects. But I want to include things like "com.google.chrome", because it's an app in the app drawer, but is technically installed as a system app.

I debugged into the ApplicationInfo list returned from the Package Manager, and found that some apps have an Int Icon value of 0 or something else (1254865, etc). So I tried:

List<ApplicationInfo> allApps = Utilities.getAllApps(mContext);
List<ApplicationInfo> visibleApps = new ArrayList<>();
for (ApplicationInfo appInfo : allApps) {
    if (appInfo.icon != 0) {
      visibleApps.add(appInfo);
    }
}

This helped me get closer, but on my stock emulator, there's 100 "allApps", and this logic helped me drill down to 54 apps. But there's only 25 apps in the drawer... Update: Android may have moved away from this implementation with newer API versions.


Solution

  • Is this app visible in the app drawer?

    If, by "app drawer", you are referring to a home screen launcher, the decision of what to show there is up to the developers of the home screen launcher.

    You can find out what activities are being offered to show in the home screen launcher via PackageManager and queryIntentActivities(), looking for ACTION_MAIN/CATEGORY_LAUNCHER activities. From there, you could derive a list of apps that offer those activities (bearing in mind that any app might offer 0, 1, or several such activities).