Tuesday, September 10, 2013

Android Tip - Checking Availability of Google Play Services


Nowadays, most of the services in Android are encapsulated in Google Play Services. For example, the latest version of Google Maps for Android is based on the Google Play services APK. Another feature that is based on Google Play services is the Fused Location Provider. Moving all the critical services into the Google Play services APK allows Google to deliver updates to core services much more quickly, without replying on carrier or OEM system image updates.

As such, it is important that your application checks the device that it is running on to ensure that the device has the Google Play services APK installed.

You can make use of the isGooglePlayServicesAvailable() method from the GooglePlayServicesUtil class to check if the target device has the Google Play services APK:

import com.google.android.gms.common.GooglePlayServicesUtil;
...
        int resultCode = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(this);
        // ---if Google Play services is available---
        if (ConnectionResult.SUCCESS == resultCode) {
            Log.d("Location Updates",
                "Google Play services is available.");
        } else {
            //---Google Play services was not available for
            // some reason---
            Log.d("Location Updates",
                "Google Play services is not available."); 
        }

No comments: