Listing all apps on Android with SDK level 31

55 views Asked by At

I'm trying to list all the installed applications to create a simple launcher, but despite following every available tutorial I still can't get to the result that I want.

I even tried copying code from other launchers, but even in that case I don't get the same apps that I can see in my emulator.

I'm targeting API level 31 and this is what I'm doing:

AndroidManifest.xml

<queries>
    <intent>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.action.LAUNCHER"/>
    </intent>
</queries>

ApplicationRepository.kt

applications = context.packageManager.getInstalledApplications(PackageManager.MATCH_UNINSTALLED_PACKAGES)

(getting the same result with the GET_META_DATA flag)

On my emulator, stock launcher shows 13 apps while my code retrieves 73 of them and the ones that I can see on the launcher are not even there.

Adding the QUERY_ALL_PACKAGES permission kind of works, even if I would then have to manually filter the returned packages, but from my understanding this is a bad practice so I'm trying to avoid it.

To be fair, even upon reading the official documentation, I still don't understand why I'm not getting the results that I want.

The queries tag should be enough to list all the packages that can be launched from a launcher, so why am I getting lots of system packages and none of the installed apps?

What am I doing wrong?

0

There are 0 answers