Search code examples
androidbuild.gradleandroid-package-managerstarget-sdk

PackageManager not returning correct packages with targetSdkVersion 30


I am using the PackageManager to get a list of all packages installed on the user's device. This is working perfectly fine, until I switch from targetSdkVersion 29 to 30.

When I increase the targetSdkVersion from 29 to 30, the PackageManager is not returning the correct list of packages anymore (I'm making a launcher and in fact, it is barely returning any packages that can be launched).

I tried pm.getInstalledPackages(0), pm.getInstalledApplications(0) and the method for retrieving apps as indicated here. None of them worked, and all of them were working previously.

The build.gradle version settings:

compileSdkVersion 30
defaultConfig {
    minSdkVersion 23
    targetSdkVersion 29
}

Does anyone have an idea of what is happening here?


Solution

  • As @ephemient pointed out in his comment of his answer, using <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/> solved it.

    This is done because of the restricted access apps have from Android 11 onwards, as this article explains well.