I would like your help on something, I'm developing an app using firebase, so it works and needs google play services relatively up-to-date. In my tests, in outdated versions the crash app. I some applications when it is necessary a certain version of google play service appears a notification requesting the user to update google play service, this is my doubt, how do I make this message appear?
5 Answers
You can do it as follows:
final GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
final int status = googleApiAvailability .isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
//Status that you are interested is SERVICE_VERSION_UPDATE_REQUIRED
final Dialog dialog = googleApiAvailability.getErrorDialog(this,status, 1);
dialog.show();
}
Note:
GooglePlayServicesUtil.isGooglePlayServicesAvailable(context)
has been deprecated.

- 23,903
- 4
- 62
- 62
-
@PriyankPatel you can get value of `GOOGLE_PLAY_SERVICES_VERSION_CODE` which returns, client library version – Sagar May 30 '18 at 05:42
-
@Sagar Thanks for the reply, this code worked almost as I want, the only problem is that when I click on the message to update google play service nothing happens, I need to do something else to redirect the user? – DouglasNickson May 30 '18 at 12:48
-
@DouglasNickson Ideally you dont need to do anythig. By clicking ot it, itwill direct l to the Play Store if Google Play services is out of date or missing, or to system settings if Google Play services is disabled on the device – Sagar May 30 '18 at 12:54
You have 2 options to do that. Look at below code
private boolean checkPlayServices() {
GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance();
int resultCode = apiAvailability.isGooglePlayServicesAvailable(context);
if (resultCode != ConnectionResult.SUCCESS) {
// Handle 1
// Show own dialog for status
if (resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED) {
// This is the case, where update required for google play service
} else {
// This would be case like, play services not available on device and needs to install
}
// Handle 2
// Or you can depend on library classes to handle these eror and show appropriate error message with action in dialog.
if (apiAvailability.isUserResolvableError(resultCode)) {
apiAvailability.getErrorDialog(this, resultCode, PLAY_SERVICES_RESOLUTION_REQUEST)
.show();
} else {
// Unrecoverable error.
}
return false;
}
return true;
}
In above code // Handle 1
and // Handle 2
are two ways of doing that. In most of the cases // Handle 2
is better option. For more error handling in you want (not related to this question), you should read How to check Google Play services version?

- 81,967
- 29
- 167
- 186
private boolean checkGooglePlayServices() {
final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
Log.e(TAG, GooglePlayServicesUtil.getErrorString(status));
// need to update google play services.
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, 1);
dialog.show();
return false;
} else {
Log.i(TAG, GooglePlayServicesUtil.getErrorString(status));
// google play services is updated.
return true;
}
}
try with this.

- 1,968
- 1
- 8
- 13
You can check version using below code of GoogleApiAvailability
GoogleApiAvailability.GOOGLE_PLAY_SERVICES_VERSION_CODE
First you need to check, if Google play service available or not using below API.
public int isGooglePlayServicesAvailable (Context context)
OR
You can directly check using below API.
public int isGooglePlayServicesAvailable (Context context, int minApkVersion)
Verifies that Google Play services is installed and enabled on this device, and that the version installed on this device is no older than the one required by this client or specified in minApkVersion.

- 12,244
- 8
- 65
- 85
//Check for play service availablity
int available=GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
if(available!= ConnectionResult.SUCCESS) {
if(available== ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED){
Toast.makeText(this,"please update your google play service",Toast.LENGTH_SHORT).show();
}
else {
Toast.makeText(this, "please download the google play service", Toast.LENGTH_SHORT).show();
}
}

- 399
- 2
- 4