Home > Software design >  How do I get ALL installed apps on the phone?
How do I get ALL installed apps on the phone?

Time:03-10

I've tried using both getInstalledApplications and getInstalledPackages, both seem to only give the default apps. I said only the default apps but this isn't necessarily true either. When I run the app on an AVD (api 29), it will include youtube. When I run it on my actual phone (31) it doesn't show youtube even though youtube is a default app on my phone. I'm not sure what to try from here.

This is how ive tried getting the app info.

            val packManager: PackageManager = packageManager
            val allPackages: MutableList<ApplicationInfo> = packManager.getInstalledApplications(PackageManager.GET_META_DATA)
                //packManager.getInstalledPackages(PackageManager.GET_META_DATA)

            val packages: MutableList<ApplicationInfo> = mutableListOf<ApplicationInfo>()
            //getting app info for "main apps" that can actually be opened
            for (i in allPackages) {
                if (packManager.getLaunchIntentForPackage(i.packageName) != null) {
                    packages.add(packages.size, packManager.getApplicationInfo(i.packageName, 0))
                }
            }

CodePudding user response:

Your code definitely works, you just need to add the permission in your Manifest file

    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"
    tools:ignore="QueryAllPackagesPermission" />

Keep in mind that if you publish to the play store, your app will be subject to inspection because application queries are sensitive information.

  • Related