앱이 설치되었는지 판단하는 함수:
fun Context.isInstalledApp(packageName: String): Boolean {
val intent = packageManager.getLaunchIntentForPackage(packageName)
return intent != null
}
특정 앱을 실행하는 함수:
fun Context.openApp(packageName: String) {
val intent = packageManager.getLaunchIntentForPackage(packageName)
startActivity(intent)
}
마켓으로 이동하는 함수
fun Context.market(packageName: String): Boolean {
return try {
val intent = Intent(Intent.ACTION_VIEW)
intent.data = Uri.parse("market://details?id=$packageName")
startActivity(intent)
true
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
false
}
}