Android 8 or higher: Check for Google Play Services

13,847

Solution 1

It is returning SUCCESS. The documentation clearly states that the method had an int return type, and returns a

status code indicating whether there was an error. Can be one of following in ConnectionResult: SUCCESS, SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID.

To check against what was returned, use something like:

int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if(status == ConnectionResult.SUCCESS) {
    //Success! Do what you want
}

Solution 2

Please read the documentation: 0 is SUCCESS

public static final int SUCCESS
The connection was successful.
Constant Value: 0 (0x00000000)

Documentation

Solution 3

Simply

int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (statusCode == ConnectionResult.SUCCESS) {
    //OK
}

Solution 4

int state = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        if (state == ConnectionResult.SUCCESS) {
            Toast.makeText(this, "SUCCESS", Toast.LENGTH_LONG).show();
            //goAhead();
        } else {
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(state, this, -1);
            dialog.show();
        }
Share:
13,847
Mark Molina
Author by

Mark Molina

Co-Owner of De Nederlandse Wateren http://www.denederlandsewateren.nl/ Owner of CleverCode http://www.clevercode.nl/ iOS and Android developer LinkedIn: http://nl.linkedin.com/pub/mark-molina/54/45/186/

Updated on July 21, 2022

Comments

  • Mark Molina
    Mark Molina almost 2 years

    this method keep returning 0. According to the developer docs this method should return something like SUCCES if the device got the newest version of google play. Does anybody know how to use this?

    @Override
        public void onResume() {
            super.onResume();
    
            GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
            System.out.println("henkie: " + GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()));
        }
    
  • Varun Goyal
    Varun Goyal almost 9 years
    missing a ) int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getAppl‌​icationContext()); if(status == ConnectionResult.SUCCESS) { //Success! Do what you want }
  • Saravanabalagi Ramachandran
    Saravanabalagi Ramachandran over 8 years
    isGooglePlayServicesAvailable is deprecated