Launch external App

Open Google Play Store if the external app is not installed on your device otherwise open the app

private fun launchApp(appPackageName: String) {

        if (appInstalledOrNot(appPackageName)) { 
            val intent: Intent = context?.packageManager?.
                getLaunchIntentForPackage(appPackageName)!!
            startActivity(intent)
        } else {

            try {
                startActivity(
                    Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=$appPackageName")
                    )
                )
            } catch (exception: ActivityNotFoundException) {
                startActivity(
                    Intent(
                        Intent.ACTION_VIEW,
                        Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName")
                    )
                )
            }
        }

    }

Post Suggeriti