Muhammad Ahmed AbuTalib Muhammad Ahmed AbuTalib - 14 days ago 7
Android Question

Checking for google play services

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.

Answer

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)));
}