In my application, I need to check Google Play services version (which is installed in user's device). Is it possible ? And if yes, how can I do that?
12 Answers
I found simple solution:
int v = getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0 ).versionCode;
But versionCode
is deprecated in API 28, so you can use PackageInfoCompat
:
long v = PackageInfoCompat.getLongVersionCode(getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0 ));

- 8,084
- 8
- 48
- 62

- 6,544
- 15
- 41
- 54
-
8How to know the version code of play services version 10.2 – Manmohan Soni Jun 12 '18 at 09:01
-
Since versionCode is deprecated with API28 you should use [PackageInfoCompat.getLongVersionCode](https://developer.android.com/reference/androidx/core/content/pm/PackageInfoCompat.html#getLongVersionCode) – G00fY Nov 04 '18 at 14:36
If you look in the link provided by Stan0 you will see this:
public static final int GOOGLE_PLAY_SERVICES_VERSION_CODE
Minimum Google Play services package version (declared in AndroidManifest.xml android:versionCode) in order to be compatible with this client version. Constant Value: 3225000 (0x003135a8)
So, when you set that in your manifest and then call isGooglePlayServicesAvailable(context)
:
public static int isGooglePlayServicesAvailable (Context context)
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.
Returns
- status code indicating whether there was an error. Can be one of following in ConnectionResult:
SUCCESS
,SERVICE_MISSING
,SERVICE_VERSION_UPDATE_REQUIRED
,SERVICE_DISABLED
,SERVICE_INVALID
.
It will ensure that the device is using the version your app requires, if not, then you can take action according to the documentation
Edit
GooglePlayServicesUtil.isGooglePlayServicesAvailable()
is deprecated and now GoogleApiAvailability.isGooglePlayServicesAvailable()
should be used instead.

- 6,405
- 16
- 66
- 120

- 1,912
- 14
- 21
-
3GoogleApiAvailability is now a singleton so you should use: GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity) – Nativ Nov 28 '17 at 09:33
-
@Nativ is there any way to check that whether the google play services version running on android device is greater than 10.2 or not – Manmohan Soni Jun 12 '18 at 09:05
-
@ManmohanSoni I'm sure there is. I'm currently shifted to iOS development so I cannot be much of an help for you. – Nativ Jun 12 '18 at 10:44
Here is my solution:
private boolean checkGooglePlayServices() {
final int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
Log.e(TAG, GooglePlayServicesUtil.getErrorString(status));
// ask user 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.
//your code goes here...
return true;
}
}
and you have two options, either write your code directly in else block as commented, or use the returned boolean value for this method to write custom code.

- 6,405
- 6
- 28
- 69

- 6,465
- 6
- 36
- 43
IMPORTANT: GoogleApiAvailability.GOOGLE_PLAY_SERVICES_VERSION_CODE returns the minimum version required by YOUR app, not the play services version that is installed on the user's device.

- 3,669
- 2
- 31
- 45
int status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
if(status != ConnectionResult.SUCCESS) {
if(status == 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();
}
}

- 87
- 3
- 11

- 559
- 5
- 5
From newer updates i have ended up with this code, i have made a handy method to manage all stuff related to it..
All details related to availability of Service and related details are available here.
private void checkPlayService(int PLAY_SERVICE_STATUS)
{
switch (PLAY_SERVICE_STATUS)
{
case ConnectionResult.API_UNAVAILABLE:
//API is not available
break;
case ConnectionResult.NETWORK_ERROR:
//Network error while connection
break;
case ConnectionResult.RESTRICTED_PROFILE:
//Profile is restricted by google so can not be used for play services
break;
case ConnectionResult.SERVICE_MISSING:
//service is missing
break;
case ConnectionResult.SIGN_IN_REQUIRED:
//service available but user not signed in
break;
case ConnectionResult.SUCCESS:
break;
}
}
I use it like this,
GoogleApiAvailability avail;
int PLAY_SERVICE_STATUS = avail.isGooglePlayServicesAvailable(this);
checkPlayService(PLAY_SERVICE_STATUS);
And for version GoogleApiAvailability.GOOGLE_PLAY_SERVICES_VERSION_CODE;
will give you.
And one of the most useful answer i found during my research is here.
int apkVersion = GoogleApiAvailability.getInstance().getApkVersion(getContext());
will get the same result as:
int v = getPackageManager().getPackageInfo(GoogleApiAvailability.GOOGLE_PLAY_SERVICES_PACKAGE, 0 ).versionCode;
But the second one needs to be put inside a try-catch.

- 51
- 4
I’ve run into the same problem this morning. And got it done by the advice from stan0. Thanks stan0.
Only one change is needed based on the sample code from https://developers.google.com/maps/documentation/android/map.
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
if (mMap == null) {
FragmentManager mgr = getFragmentManager();
MapFragment mapFragment = (MapFragment)mgr.findFragmentById(R.id.map);
mMap = mapFragment.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
// The Map is verified. It is now safe to manipulate the map.
setUpMap();
}else{
// check if google play service in the device is not available or out-dated.
GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
// nothing anymore, cuz android will take care of the rest (to remind user to update google play service).
}
}
}
Besides, you need to add an attribute to your manifest.xml as:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="your.package.name"
android:versionCode="3225130"
android:versionName="your.version" >
And the value of "3225130" is taken from the google-play-services_lib that your project is using. Also, that value is residing in the same location of manifest.xml in google-play-services_lib.

- 6,405
- 6
- 28
- 69

- 428
- 1
- 4
- 10
If you look up Google Play Services in the Application manager it will show the version installed.

- 43
- 2
-
I haven't tried the other programmatic approaches listed in other answers but searching in the application manager worked for me, thanks! – user62171 Oct 20 '16 at 20:31
Updated (2019.07.03) Kotlin version:
class GooglePlayServicesUtil {
companion object {
private const val GOOGLE_PLAY_SERVICES_AVAILABLE_REQUEST = 9000
fun isGooglePlayServicesWithError(activity: Activity, showDialog: Boolean): Boolean {
val status = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(activity)
return if (status != ConnectionResult.SUCCESS) {
if (showDialog) {
GoogleApiAvailability.getInstance().getErrorDialog(activity, status, GOOGLE_PLAY_SERVICES_AVAILABLE_REQUEST).show()
}
true
} else {
false
}
}
}
}

- 3,446
- 5
- 33
- 46
Use the following function to check if google play services could be used or not
private boolean checkGooglePlayServicesAvailable() {
final int connectionStatusCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (GooglePlayServicesUtil.isUserRecoverableError(connectionStatusCode)) {
showGooglePlayServicesAvailabilityErrorDialog(connectionStatusCode);
return false;
}
return true;
}
int registeredVersion = prefs.getInt(PROPERTY_APP_VERSION, Integer.MIN_VALUE);
int currentVersion = getAppVersion(context);
if (registeredVersion != currentVersion) {
Log.i(TAG, "App version changed.");
return "";
}

- 303
- 3
- 14