Android package manager를 이용하세요.
https://developer.android.com/reference/android/content/pm/PackageManager
코틀린으로 해당 앱이 설치되었는지 체크하는 간단한 코드입니다. 첫번째 인자는 application id입니다.
fun isAppInstalled(appId: String): Boolean {
return try {
packageManager.getPackageInfo(appId", 0)
true
} catch (e: PackageManager.NameNotFoundException) {
false
}
}
아래은 해당 앱의 플레이스토어 페이지를 여는 코드입니다.
fun openPlayStore(appId: String) {
try {
openPlayStoreApp(appId)
} catch (e: ActivityNotFoundException) {
openPlayStoreWebPage(appId)
}
}
fun openPlayStoreApp(appId: String) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$appId")))
}
fun openPlayStoreWebPage(appId: String) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=$appId")))
}
액티비티에서 아래처럼 사용하면 됩니다.
val appId = "찾으려는 앱의 패키지이름"
if (!isAppInstalled(appId)) {
openPlayStore(appId)
return
}