How to check if a package is installed in android Kotlin programmatically for android 12+?

Issue

To Check if a package is installed in android Kotlin programmatically for android 12+. Without declaring a query in the manifest file for Android 12+(API 31+).

Solution

private fun isAvailable(ctx: Context, intent: Intent?): Boolean {
    val mgr = ctx.packageManager
    val list = mgr.queryIntentActivities(intent!!, PackageManager.MATCH_DEFAULT_ONLY)
    return list.size > 0
}

Use this code snippet for that, Thanks.

Answered By – Udit Bhaskar

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published