i want to work with google cloud messaging for my android app. it is said that you need to check for google play services availability first. but i don't know how to implement this. just searched through GoogleApiAvailability Class. Problem is i don't understand how to set up check and use method .getErrorDialog() in my case. It is said requestCode is "The requestCode given when calling startActivityForResult". but how to use it?
public void onResume() {
GoogleApiAvailability availability = GoogleApiAvailability.getInstance();
int checkForGPS = availability.isGooglePlayServicesAvailable(this);
if(checkForGPS != ConnectionResult.SUCCESS) {
availability.getErrorDialog(this, checkForGPS, requestCode);
}
super.onResume();
}
Try this,
private boolean checkPlayServices() {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, this, PLAY_SERVICES_RESOLUTION_REQUEST).show();
} else {
Log.e(TAG, "This device is not supported.");
finish();
}
return false;
}
return true;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments