Last active
August 29, 2015 14:11
-
-
Save adamcmwilson/b806bd0e17667549c758 to your computer and use it in GitHub Desktop.
Google Play Services Update Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final GMSUtil.PlayServicesState state = GMSUtil.getPlayServicesState(getContext()); | |
| if (state.isReady()) { | |
| // USE GOOGLE PLAY APIS | |
| } else { | |
| // DONT USE GOOGLE PLAY APIS | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 + | |
| '}'; | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://developer.android.com/google/play-services/setup.html#ensure