diff options
Diffstat (limited to 'library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt')
-rw-r--r-- | library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt index 642c29c..8aaadaf 100644 --- a/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt +++ b/library/src/main/kotlin/ca/allanwang/kau/utils/Utils.kt @@ -1,9 +1,13 @@ package ca.allanwang.kau.utils +import android.content.Context import android.content.res.Resources import android.os.Build import android.os.Looper import ca.allanwang.kau.logging.KL +import android.content.pm.PackageManager + + /** * Created by Allan Wang on 2017-05-28. @@ -27,4 +31,21 @@ val buildIsMarshmallowAndUp: Boolean fun checkThread(id: Int) { val status = if (Looper.myLooper() == Looper.getMainLooper()) "is" else "is not" KL.d("$id $status in the main thread") +} + +/** + * Checks if a given package is installed + * @param packageName packageId + * @return true if installed with activity, false otherwise + */ +fun Context.isAppInstalled(packageName: String): Boolean { + val pm = packageManager + var installed: Boolean + try { + pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES) + installed = true + } catch (e: PackageManager.NameNotFoundException) { + installed = false + } + return installed }
\ No newline at end of file |