Search code examples
androidandroid-7.0-nougatandroid-package-managers

PackageManager.getInstalledApplications(0); in Android 7.0


My problem is that I use package manager to list all the installed applications

final PackageManager pm = parentActivity.getPackageManager();
List<ApplicationInfo> packages = pm.getInstalledApplications(0);

With this code I can list successfully all the applications in other versions of android except in Android 7.0 (which only list the app that I'm using), can anyone knows why this is happening and how to solve it?


Solution

  • Try the below code. It is working fine for me:

    final PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(0);
    
    for (ApplicationInfo applicationInfo : packages) {
        Log.d("APP_INFO", "App: " + applicationInfo.name + " Package: " + applicationInfo.packageName);
    }
    

    Tested on Android 6, 7 and 8

    Hope this will help!