innovationM
← Back to Blogs

Android

Ensure Google Play Services APK is updated

InnovationM Admin 05 Feb 2018 2 min read
Ensure Google Play Services APK is updated

If your app is using any Google API in your project, then you need to make sure that your device has Google Play Services APK updated.

Firstly, you have to decide the accurate position where you need to insert the code to update Google Play Services.

If your app is entirely based on Google Play Services, then you can do this at the time your app launches initially. However, if only a part of your app uses Google Play Services, then you should do it whenever user needs to access that part of your app.

Now there are two ways to check availability of Google Play Services :

  1. Using GooglePlayServicesUtil
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());

if(status != ConnectionResult.SUCCESS)
{
        if(status == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED)
        {
            Toast.makeText(context,"Please udpate your google play services",Toast.LENGTH_SHORT).show();
        }
}

But the problem with this approach is that some methods and fields of GooglePlayServicesUtil have been deprecated.

So, the second and better approach (which google also recommends) is

2. Using GoogleApiAvailability

GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance();

int result = googleAPI.isGooglePlayServicesAvailable(activity);

if(result != ConnectionResult.SUCCESS)
{
   if (googleAPI.isUserResolvableError(result)) 
   {
      googleAPI.getErrorDialog(activity, result, AppConstant.PLAY_SERVICES_RESOLUTION_REQUEST).show();
   }
}

This will show you a Dialog containing an appropriate message about the error occured and the required action that will take you to play store to install or update Google Play Services.

Finally, your device will have Google Play Services up-to-date!!

About the Author

InnovationM Admin

Contributor at InnovationM.

LinkedIn

Transform Your Ideas with Expert Guidance

icon
15+ Years of Expertise

Delivering high-impact solutions with years of industry experience.

icon
100+ Satisfied Clients

Helping contact industry software experts to achieve their brand goals.

icon
250+ In-House Team Members

A skilled team ready to tackle projects of any scale.

Book a consultation call with our experts today