How to check Google Play services version?

前端 未结 12 1181
走了就别回头了
走了就别回头了 2020-11-28 03:44

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? I searched Google but

12条回答
  •  执笔经年
    2020-11-28 04:20

    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.

提交回复
热议问题