Reputation: 4292
It drives me crazy how important documentation is often overlooked in the google docs. I would have plucked out my hair if I wasn't bald already.
private void checkGooglePlayServices() {
int errorCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
boolean isErrorResolvable = GoogleApiAvailability.getInstance().isUserResolvableError(errorCode);
if (isErrorResolvable) {
GoogleApiAvailability.getInstance().getErrorDialog(this, errorCode, REQUEST_CODE_GOOGLE_PLAY_SERVICES).show();
} else {
if (errorCode == ConnectionResult.SUCCESS) {
launchApplication();
}
}
}
The above code displays a Dialog box which says has a button reading get google play services:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_GOOGLE_PLAY_SERVICES) {
}
}
now what should I do here ? How should I direct the user to the play store to get an update for the playservices? I deem
getErrorResolutionPendingIntent
to be of use here, but I am not sure how to go about this.
please aid me.
Upvotes: 0
Views: 1431
Reputation: 1591
You can use this code to open Google Play Service Page on App Store:
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE)));
}
Upvotes: 2
Reputation: 1799
You can check Google Play Service with this:
if (checkPlayServices()) {
// Do your calculation here.
}
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
} else {
Log.i(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
This will help you to check Google Play Service.
Upvotes: 3