I can easily detect that my device's google play services app needs to be updated, and present the getErrorDialogFragment() to prompt the user to update it with:
GoogleApiAvailability googleApi = GoogleApiAvailability.getInstance();
mServiceAvailabilityCode = googleApi.isGooglePlayServicesAvailable(this);
if (mServiceAvailabilityCode == ConnectionResult.SUCCESS) {
...
else {
if (googleApi.isUserResolvableError(mServiceAvailabilityCode)) {
switch (mServiceAvailabilityCode) {
....
case SERVICE_VERSION_UPDATE_REQUIRED:
googleApi.showErrorDialogFragment(SplashActivity.this, mServiceAvailabilityCode, PLAY_SERVICES_RESOLUTION_REQUEST);
break;
....
}
However, if Google play services is disabled AND out of date, then, the user is presented with a dialog with an "Update" button, once the user presses it, the app returns immediately to the onActivityResult, which I then catch the response and request code in OnActivityResult like this:
@Override
protected void onActivityResult(int requestCode, int mServiceAvailabilityCode, Intent data) {
super.onActivityResult(requestCode, mServiceAvailabilityCode, data);
switch (requestCode) {
case PLAY_SERVICES_RESOLUTION_REQUEST:
finish();
// do i need to launch app manager-> app info for google play services ?
So, by the user pressing the "Update" button on the dialog did not launch Android's Playstore and load the "Playstor services" app for the user to update, which I had expected it to do. Pressing "Update" just goes straight back to onActivityResult. This is where I'm confused. Shouldn't Android have launched this for me ? Or do I have to do it myself in OnActivityResult ?
If still you cannot update Google Play Services, clearing cache can solve your problem. We also stated about this in the beginning as the reason. If you don't know, cache holds the app's data temporarily so that it can remember the information when you next open the app. Many times, old cache files get corrupted.
Restart Your Phone If an app or a background service on your phone is causing Google Play Services to crash, restarting the phone would clear it off the RAM and put the device in a new state. Depending on the Android phone you own, you can reboot it either by turning it off and on or by using the restart option.
To update Google Play Services on your Android device, head to the "Apps & Notifications" menu in your settings. Google Play Services let your Android apps connect to the internet and communicate with Google. Updating Google Play Services can fix app issues, and help your Android device run faster.
The problem is caused by a specific condition when you have 2 issues with Google Play Services (GPS). Because GPS is also disabled Google Play Store (GPT), will not run on the device.
If your Google Play Services is out of date, then calling showErrorDialogFragment using an error code of ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED
, (error code 2), which works fine.
But if your GPS is both disabled AND out-of-date, then there is an issue with the way googleApiAvailability
api works.If you call isGooglePlayServicesAvailable()
it will return the first error it finds, but it's not necessarily the error you want to resolve first. The problem is knowing that you have another error you need to address first. isGooglePlayServicesAvailable()
does not help in this regard.
In my case play services is both disabled, AND out of date. So, the approach is to first call showErrorDialogFragment and you'll get a response error code for SERVICE_VERSION_UPDATE_REQUIRED
.
Android will attempt to resolve it by sending a pendingIntent to launch Google Play Store (GPT) to update GPS, but this will fail, as GPT depends on an ENABLED version of GPS. Because you're calling showErrorDialogFragment it will call onActivityResult after it fails to launch GPT.
The next step is codig the onActivityResult. I needed to test for isGooglePlayServicesAvailable()
again. If you still get the same error code (SERVICE_VERSION_UPDATE_REQUIRED), then you need to call showErrorDialogFragment again in onActivityResult
, but this time pass it a different error code, ConnectionResult.SERVICE_DISABLED
(error code 3). This will take the user to the app manager to ENABLE google play services first. Then when returning to the app, you need to test for isGooglePlayServicesAvailable
and it should then detect google services is still out of date. If you successfully update the app, onActivityResult
should allow you to determine that isGooglePlayServicesAvailable
is succcessful and you can continue. Note that you will may need to add a flag that so that you know to test again for google play services compatibility rather than continue executing a startup process.
(So, really what googleApiAvailability should do is return the disabled error first (ie ConnectionResult.SERVICE_DISABLED
aka error code 3), so you can resolve that first before attempting to update GPS.)
This is working for me
GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();
int result = googleAPI.isGooglePlayServicesAvailable(this);
if(result != ConnectionResult.SUCCESS) {
if(googleAPI.isUserResolvableError(result)) {
//prompt the dialog to update google play
googleAPI.getErrorDialog(this,result,PLAY_SERVICES_RESOLUTION_REQUEST).show();
}
}
else{
//google play up to date
}
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