Skip to content

Instantly share code, notes, and snippets.

@TylerMills
Created July 2, 2019 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylerMills/d6ebc0d8e4d68f32a9992843a6250792 to your computer and use it in GitHub Desktop.
Save TylerMills/d6ebc0d8e4d68f32a9992843a6250792 to your computer and use it in GitHub Desktop.
// Update Google Play Services
// The latest Google Play Services update must be installed on the user's device for functionality to work properly. Ensure that the user has the latest update as follows.
// In your MainActivity create a unique request code as follows.
private static final int REQUEST_GOOGLE_PLAY_SERVICES = 100;
// In onResume() of your MainActivity, check for Google API availability and prompt the user to update if neccessary as follows.
@Override
protected void onResume() {
super.onResume();
GoogleApiAvailability api = GoogleApiAvailability.getInstance();
int code = api.isGooglePlayServicesAvailable(this);
if (code == ConnectionResult.SUCCESS) {
// The device's Google Play Services version is up to date
// If you are integating Push, add the following line:
// register for push
} else if (api.isUserResolvableError(code)) {
if (!api.showErrorDialogFragment(this, code, REQUEST_GOOGLE_PLAY_SERVICES)) {
Toast.makeText(this, api.getErrorString(code), Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, api.getErrorString(code), Toast.LENGTH_LONG).show();
}
}
// Handle the Google Play Services request code as follows.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case REQUEST_GOOGLE_PLAY_SERVICES:
if (resultCode == Activity.RESULT_OK) {
// The device's Google Play Services version is up to date
// If you are integating Push, register here
}
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment