Hello I am trying to use the GCM
in android application where it is require to check whether use has Google Play Service
installed or not. For this I have coded but I don't how to handle the situation when user do not have Google Play Service
installed.
Is there any in built a way to give prompt user to install the Google Play Service
and redirect it to play store to install it.
/**
* Check the device to make sure it has the Google Play Services APK. If
* it doesn't, display a dialog that allows users to download the APK from
* the Google Play Store or enable it in the device's system settings.
*/
public static boolean checkPlayServices(Context mContext) {
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(mContext);
if (resultCode != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(resultCode)) {
GooglePlayServicesUtil.getErrorDialog(resultCode, (Activity)mContext,Constants.PLAY_SERVICES_RESOLUTION_REQUEST).show();
}
return false;
}
return true;
}
// here check whether device has google play service installed // if it is installed then register the device with the GCM // otherwise redirect user to play store to install it.
if(Utils.checkPlayServices(getActivity())) {
new RegisterGCMDeviceAsynTask(new TaskCompleteListener() {
@Override
public void onTaskCompleted(String result) {
new TeemWurkAsyncTask(new TaskCompleteListener() {
@Override
public void onTaskCompleted(String result) {
Logger.d(TAG, result);
}
}, Constants.LOGIN_API_CALL).execute("");
}
}).execute();
} else {
// display the dialog that device do not have Google Play Service installed.
}
Clear Cache and Data This fix will also be useful when troubleshooting other apps. Open Settings on your Android phone. Tap on “Apps” and “Google Play Services” under the “All apps” section. Select “Storage,” then press the “Clear cache” button followed by the “Clear data” or “Clear storage” button.
After you uninstall Google Play Services, you might meet quite a few troubles, like messages problems, network issues, app crashing, etc. Your apps related to Google will not work properly, like Gmail, Google Maps, Google Music, etc. You may have to say goodbye to Google Play.
Something like this :
if(!isGooglePlayServicesAvailable()) {
GooglePlayServicesUtil.getErrorDialog(9999, this, RQS_GooglePlayServices).show();
}
9999 is the request code (a random integer) used in onActivityResult()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With