Site icon 咖啡偶-IT日常

android 檢查play store是否安裝

java

public static boolean isPlayStoreInstalled(Context context){
    try {
        context.getPackageManager()
                .getPackageInfo(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE, 0);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}

kotlin

fun isPlayStoreInstalled(context: Context): Boolean {
    return try {
        context.packageManager
            .getPackageInfo(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE, 0)
        true
    } catch (e: PackageManager.NameNotFoundException) {
        false
    }
}

build.gradle

    implementation 'com.google.android.gms:play-services-base:18.0.1'
Exit mobile version