问题
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()));
}
回答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
}
回答2:
Please read the documentation: 0 is SUCCESS
public static final int SUCCESS
The connection was successful.
Constant Value: 0 (0x00000000)
Documentation
回答3:
Simply
int statusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (statusCode == ConnectionResult.SUCCESS) {
//OK
}
回答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();
}
来源:https://stackoverflow.com/questions/13766592/android-8-or-higher-check-for-google-play-services