Cannot determine whether Google play store is installed or not on Android device

后端 未结 5 1199
自闭症患者
自闭症患者 2020-12-08 21:27

This was a simple matter of checking the installed packages on the device... before I\'ve upgraded my OS to 2.3.5, I could locate the Market/Play store, using this code:

5条回答
  •  一生所求
    2020-12-08 22:02

    Be aware that this almost 5 years old code is not optimal and Google does not like when you check all installed packages without no good reason. Please check also the other answers.

    The package name has changed, it is now com.android.vending


    Try:

    private static final String GooglePlayStorePackageNameOld = "com.google.market";
    private static final String GooglePlayStorePackageNameNew = "com.android.vending";
    
    void someMethod() {
        PackageManager packageManager = getApplication().getPackageManager();
        List packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
        for (PackageInfo packageInfo : packages) {
            if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
                packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
                googlePlayStoreInstalled = true;
                break;
            }
        }
    }
    

提交回复
热议问题