Created
May 6, 2015 06:46
-
-
Save allenchi/6c335428321b8a7530f6 to your computer and use it in GitHub Desktop.
Check Google Play Service
This file contains 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
// check if a compatible play services is available on the device | |
// if not, show a dialog that takes the user to Google Play Store | |
// to install the required play service | |
private boolean checkPlayServices() { | |
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); | |
if (status != ConnectionResult.SUCCESS) { | |
if (GooglePlayServicesUtil.isUserRecoverableError(status)) { | |
showErrorDialog(status); | |
} else { | |
Toast.makeText(this, "This device is not supported.", | |
Toast.LENGTH_LONG).show(); | |
finish(); | |
} | |
return false; | |
} | |
return true; | |
} | |
// show the error dialog | |
void showErrorDialog(int code) { | |
GooglePlayServicesUtil.getErrorDialog(code, this, | |
REQUEST_CODE_RECOVER_PLAY_SERVICES).show(); | |
} | |
// a request code, you can set the value to anything you like | |
static final int REQUEST_CODE_RECOVER_PLAY_SERVICES = 3333; | |
// handles play service error dialog result | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
switch (requestCode) { | |
case REQUEST_CODE_RECOVER_PLAY_SERVICES: | |
if (resultCode == RESULT_CANCELED) { | |
Toast.makeText(this, "Google Play Services must be installed.", | |
Toast.LENGTH_LONG).show(); | |
finish(); | |
} | |
return; | |
} | |
super.onActivityResult(requestCode, resultCode, data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment