Skip to content

Instantly share code, notes, and snippets.

@adamcmwilson
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save adamcmwilson/b806bd0e17667549c758 to your computer and use it in GitHub Desktop.

Select an option

Save adamcmwilson/b806bd0e17667549c758 to your computer and use it in GitHub Desktop.
Google Play Services Update Check
final GMSUtil.PlayServicesState state = GMSUtil.getPlayServicesState(getContext());
if (state.isReady()) {
// USE GOOGLE PLAY APIS
} else {
// DONT USE GOOGLE PLAY APIS
}
import android.content.Context;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
public class GMSUtil {
public static PlayServicesState getPlayServicesState(Context context) {
String message = "";
boolean ready = false;
switch (GooglePlayServicesUtil.isGooglePlayServicesAvailable(context)) {
case ConnectionResult.SUCCESS:
message = "Google Play Services Ready...";
ready = true;
break;
case ConnectionResult.SERVICE_MISSING:
message = "Google Play Services Missing...";
ready = false;
break;
case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
ready = false;
message = "A Google Play Services update is required \n to enable Cast support";
break;
case ConnectionResult.SERVICE_DISABLED:
ready = false;
message = "Google Play Services Disabled...";
break;
case ConnectionResult.SERVICE_INVALID:
ready = false;
message = "Google Play Services Invalid...";
break;
}
return new PlayServicesState(ready, message);
}
public static class PlayServicesState {
final String message;
final boolean ready;
public PlayServicesState(boolean ready, String message) {
this.message = message;
this.ready = ready;
}
public boolean isReady() {
return ready;
}
public String getMessage() {
return message;
}
@Override public String toString() {
return "PlayServicesState{" +
"message='" + message + '\'' +
", ready=" + ready +
'}';
}
}
}
@adamcmwilson
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment