0

I have used this code to get all list apps installed from user. But this code can not get all list app installed only get a part. Examle my phone have app Facebook, Messenger, Telegram ... But this code can not get those apps. My code:

private fun getInstalledApps(context: Context): ArrayList<AppInstall> {
        val mainIntent = Intent(Intent.ACTION_MAIN, null)
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
        val pkgAppsList: List<ResolveInfo> =
            context.packageManager.queryIntentActivities(mainIntent, 0)
        Log.d("TEST_LIST", pkgAppsList.size.toString())
        val res: ArrayList<AppInstall> = ArrayList<AppInstall>()
        for (i in pkgAppsList.indices) {
            val name =
                pkgAppsList[i].activityInfo.applicationInfo.loadLabel(context.packageManager)
                    .toString()
            val drawable =
                pkgAppsList[i].activityInfo.applicationInfo.loadIcon(context.packageManager)
            val bitmap: Bitmap? = drawableToBitmap(drawable)
            val idApp = pkgAppsList[i].activityInfo.packageName
            val appInstall = AppInstall(name, bitmap, idApp)
            res.add(appInstall)
        }
        return res
    }

Is there any other way to get all the apps installed on the phone ?. Thank you !
Alex
  • 61
  • 5

1 Answers1

0

You need to use the queryUsageStats method if the UsageStatsManager which will return a list of apps over the given interval.

To do so you will need permissions for Usage Access to be set in the manifest. See this question for reference:

android:name="android.permission.PACKAGE_USAGE_STATS"

ryankuck
  • 320
  • 3
  • 15