https://kotlinlang.org logo
#compose
Title
# compose
q

Qamar Khan

03/20/2023, 12:19 PM
hello Everyone. i am working on compose ui and i want to check if app is installed in phone then open application otherwise redirect to the playstore. i am able to redirect the playstore but for me, app is installed in my phone and still redirect to the playstore. can someone help me on this, or whats am missing. #compose-android
Copy code
val isAppInstalled = try {
    packageManager.getApplicationInfo(appPackageName, 0)
    true
} catch (e: PackageManager.NameNotFoundException) {
    false
}
if (isAppInstalled) {
    val launchIntent = packageManager.getLaunchIntentForPackage(appPackageName)
    startActivity(launchIntent)
} else {
    val playStoreIntent = Intent(
        Intent.ACTION_VIEW,
        Uri.parse(playStoreLink)
    )
    startActivity(playStoreIntent)
}
t

Thomas Urbanitsch

03/20/2023, 12:35 PM
First of all, not sure how you think this is related to compose ui 🤔 Secondly, have you checked if the exception is catched? If it is, are you aware of this: https://developer.android.com/training/package-visibility Pretty sure that also affects the getApplicationInfo call
5 Views