File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
utils/src/main/java/ai/elimu/common/utils Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ package ai.elimu.common.utils
2+
3+ import android.content.Context
4+ import android.content.Intent
5+ import android.content.pm.PackageInfo
6+ import android.content.pm.PackageManager
7+ import android.util.Log
8+ import androidx.appcompat.app.AlertDialog
9+
10+ fun Context.isPackageInstalled (packageName : String ,
11+ launchPackage : String ,
12+ launchClass : String ,
13+ dialogMessage : String ,
14+ buttonText : String ): Boolean {
15+ try {
16+ val packageInfoAppstore: PackageInfo =
17+ packageManager.getPackageInfo(packageName, 0 )
18+ Log .i(" isPackageInstalled" , " packageInfoAppstore.versionCode: " + packageInfoAppstore.versionCode)
19+ return true
20+ } catch (e: PackageManager .NameNotFoundException ) {
21+ Log .e(" isPackageInstalled" ," getPackageInfo exception: " + e.message)
22+ AlertDialog .Builder (this )
23+ .setMessage(dialogMessage)
24+ .setPositiveButton(buttonText
25+ ) { _, _ ->
26+ val openProviderIntent = Intent ().apply {
27+ setClassName(launchPackage, launchClass)
28+ }
29+ try {
30+ startActivity(openProviderIntent)
31+ } catch (e: Exception ) {
32+ e.printStackTrace()
33+ Log .e(" isPackageInstalled" , " startActivity exception: " + e.message)
34+ }
35+ }
36+ .setCancelable(false )
37+ .create().show()
38+ return false
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments