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

后端 未结 5 1192
自闭症患者
自闭症患者 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 21:49

    Using this code, you can check Google Play Services are installed on your device or not.

    int val=GooglePlayServicesUtil.isGooglePlayServicesAvailable(MainActivity.this);
                if(val==ConnectionResult.SUCCESS)
                {
                    play_installed=true;
                }
                else
                {
                    play_installed=false;
                }
    
    0 讨论(0)
  • 2020-12-08 21:54

    As Michael stated in the comments Google Play Services is not the same as the Google Play Store. Use this to determine whether or not the Play Store is installed on your device:

    public static boolean isPlayStoreInstalled(Context context){
        try {
            context.getPackageManager()
                    .getPackageInfo(GooglePlayServicesUtil.GOOGLE_PLAY_STORE_PACKAGE, 0);
            return true;
        } catch (PackageManager.NameNotFoundException e) {
            return false;
        }
    }
    
    0 讨论(0)
  • 2020-12-08 22:00

    In most case we want to find out whether Google Play Store is installed or not to launch it with some app page preloaded.

    Why cant we do this:

    final String appPackageName = getPackageName(); // get your app package name
    try {
        Uri uri = Uri.parse("market://details?id=" + appPackageName);
        startActivity(new Intent(Intent.ACTION_VIEW, uri));
    } catch (android.content.ActivityNotFoundException anfe) {
        // Google Play Store is not available.
    }
    
    0 讨论(0)
  • 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<PackageInfo> packages = packageManager.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES);
        for (PackageInfo packageInfo : packages) {
            if (packageInfo.packageName.equals(GooglePlayStorePackageNameOld) ||
                packageInfo.packageName.equals(GooglePlayStorePackageNameNew)) {
                googlePlayStoreInstalled = true;
                break;
            }
        }
    }
    
    0 讨论(0)
  • 2020-12-08 22:09

    GooglePlayServices has a utility class to handle this and also provide appropriated error dialogs to show according to the status of play services in the device.

    API Reference: http://developer.android.com/reference/com/google/android/gms/common/GooglePlayServicesUtil.html

    0 讨论(0)
提交回复
热议问题