i am writing an android application that showing all installed applications and apps permissions. I am writing this app. using kotlin. Is there any way to get all installed applications from package manager I AM NOT USING JAVA.
val mainIntent = Intent(Intent.ACTION_MAIN, null)
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
val pkgAppsList = context.packageManager.queryIntentActivities(mainIntent, 0)
Using the below snippet you can get details of the installed app on a device
val packages: List<ApplicationInfo> =
pm.getInstalledApplications(PackageManager.GET_META_DATA)
for (packageInfo in packages) {
Log.d(
"log",
"Installed package :" + packageInfo.packageName
)
Log.d("log", "Source dir : " + packageInfo.sourceDir)
Log.d(
"log",
"Launch Activity :" + pm.getLaunchIntentForPackage(packageInfo.packageName)
)
}
This is already answered the question here in java. I just convert that into kotlin in IDE
Code->Convert java file to Kotlin
It works fine
You can do something like this:
val packages = packageManager.getInstalledApplications(PackageManager.GET_META_DATA)
for (packageInfo in packages) {
Log.d(TAG, "Package name:" + packageInfo.packageName)
}
You can also check this article to check how it works in Android 11:
https://proandroiddev.com/how-to-get-users-installed-apps-in-android-11-b4a4d2754286
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.