1

Trying to get a list of all of the installed apps on the phone. I tried to do this (I took the code from this post and improve it):

PackageManager pm = getPackageManager();
List<ApplicationInfo> apps = pm.getInstalledApplications(0);

List<ApplicationInfo> installedApps = new ArrayList<ApplicationInfo>();

int myFlags = ApplicationInfo.CATEGORY_AUDIO |
        ApplicationInfo.CATEGORY_GAME |
        ApplicationInfo.CATEGORY_IMAGE |
        ApplicationInfo.CATEGORY_MAPS |
        ApplicationInfo.CATEGORY_NEWS |
        ApplicationInfo.CATEGORY_SOCIAL |
        ApplicationInfo.CATEGORY_VIDEO |
        ApplicationInfo.CATEGORY_UNDEFINED |
        ApplicationInfo.CATEGORY_PRODUCTIVITY;

for(ApplicationInfo app : apps) 
{
    if ( (app.flags & myFlags) != 0 && app.icon != 0) {
       installedApps.add(app);    
}

What I'm trying to get is if the app has an icon, which means it appears in the launcher, and if so I add it to my list.

For some reason some apps are missing like "YouTube" and "YT Music" and I don't understand what should I change in order to identify these applications.

Yair Lasri
  • 13
  • 2
  • "What I'm trying to get is if the app has an icon, which means it appears in the launcher, and if so I add it to my list" -- apps do not appear in the launcher. Launchable activities appear in the launcher. An app can have zero, one, or several launchable activities. "For some reason some apps are missing like "YouTube" and "YT Music" and I don't understand what should I change in order to identify these applications." -- there is no requirement for an app to declare that it belongs to a category. – CommonsWare Apr 06 '21 at 19:30

1 Answers1

0

Note that google is taking a proactive approach about privacy, It will restrict apps from fetching the device installed apps, unless asking for a specific permission called: QUERY_ALL_PACKAGES

Here's a reference from google official documentation: https://support.google.com/googleplay/android-developer/answer/10158779#zippy=%2Cinvalid-uses%2Cpermitted-uses-of-the-query-all-packages-permission

Adi Oz
  • 257
  • 1
  • 4
  • 8