skip to content

What is Google Play services on an Android device, and why should an app check it with GoogleApiAvailability before calling its APIs?

level: juniorimportance: must knowfreq 55%

answer

  1. a Google app, not the OS
  2. thin client library in your APK
  3. no Play Store, no Play services
  4. isGooglePlayServicesAvailable vs ConnectionResult.SUCCESS

basics

~20 s

Google Play services is a Google app on certified Android devices that runs the implementation behind thin client libraries for location, Maps and sign-in. Devices without the Play Store lack it, so apps check isGooglePlayServicesAvailable and offer a fix or fallback.

solid answer

~40 s

The SDKs you add, like `play-services-location` 21.4.0, are thin client libraries; at runtime they call into the Google Play services app, which updates itself through the Play Store independently of OS and OEM updates. It is not part of Android: devices without the Play Store don't have it, and on other devices it can be disabled or outdated. So before enabling a feature that needs it, call `GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)` and compare the result with `ConnectionResult.SUCCESS`. If the user can fix the problem, show `getErrorDialog` or call `makeGooglePlayServicesAvailable(activity)`, which returns a `Task`; if not, hide or replace the feature. For a single API, `checkApiAvailability(client)` returns a `Task` that fails with `AvailabilityException`.

code

kotlin · 16 lines
kotlin
class PlayServicesGate(private val activity: Activity) {
    private val availability = GoogleApiAvailability.getInstance()

    fun runWhenReady(onReady: () -> Unit, onUnavailable: () -> Unit) {
        val code = availability.isGooglePlayServicesAvailable(activity)
        if (code == ConnectionResult.SUCCESS) {
            onReady()
            return
        }
        // Prompts the user to install, enable or update Play services when that can help;
        // the Task fails when the device cannot get a usable Play services.
        availability.makeGooglePlayServicesAvailable(activity)
            .addOnSuccessListener { onReady() }
            .addOnFailureListener { onUnavailable() }
    }
}

go deeper

for a junior

Recall that Play services is a separate Google app, that your dependency is a thin client, and that isGooglePlayServicesAvailable returning ConnectionResult.SUCCESS is the green light.

for a middle

Explain the difference between a code the user can resolve, such as outdated or disabled, and a device with no Play Store, and name the dialog or makeGooglePlayServicesAvailable as the fix.

for a senior

Show where the check belongs: at each feature's entry point and again on resume, with checkApiAvailability for one API and a real fallback path rather than a crash.

for a principal

Treat the check as the visible edge of a dependency decision: which features may require Play services, and what users on devices without it still get.

## What Google Play services is **Google Play services** is a Google app that runs on Google-certified Android devices and hosts the full implementation of many Google SDKs: location, Maps, sign-in, Play Integrity and dozens more. What you add to your Gradle file is only a **lightweight client library**, for example `com.google.android.gms:play-services-location:21.4.0` or `com.google.android.gms:play-services-maps:20.0.0`. At runtime that library binds to a service inside the Play services app and forwards your calls there. Google's overview names three consequences: - **Smaller apps.** The heavy implementation is shared on the device instead of being bundled into every APK, and R8 strips the unused parts of the client libraries. - **Independent updates.** The Play services app updates itself through the Play Store, independently of the OS, the phone maker or the carrier. In general, devices running Android 7.0 (API level 24) or higher with Play services installed and enough free storage receive these updates automatically. - **Helpers for runtime problems.** The client libraries ship helpers for the cases where the service is **missing, disabled or out of date**. - **Shared plumbing.** `play-services-base` (18.11.0) and `play-services-basement` hold the utility classes such as `GoogleApiAvailability`, and `play-services-tasks` holds the `Task` API that nearly every client method returns. ## Why an app checks for it That last point is the reason for the check. Play services is not part of the Android platform itself. Google's setup guide puts it bluntly: devices without the Google Play Store don't have Google Play services installed. The overview adds that devices older than Android 7.0, or without Play services, aren't supported. Even on a certified phone the app can be disabled by the user or be older than the version your client library needs. If your app can run on such devices, the guide says to check whether Play services is installed **before** you call Google APIs or enable features that require them. ## The availability check The entry point is `GoogleApiAvailability`, in `play-services-base`: 1. Call `GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)`. It returns an `Int` result code. 2. Compare it with `ConnectionResult.SUCCESS`. Success means Play services is present, enabled and new enough. 3. For any other code, ask whether the user can fix it (install, enable or update Play services). If so, show Google's resolution UI: `getErrorDialog(...)`, `showErrorDialogFragment(...)`, or `makeGooglePlayServicesAvailable(activity)`, which returns a `Task` that succeeds once Play services is usable. 4. If nothing can fix it, hide or replace the feature instead of crashing or looping. ```kotlin val availability = GoogleApiAvailability.getInstance() val code = availability.isGooglePlayServicesAvailable(context) if (code == ConnectionResult.SUCCESS) { startLocationFeature() } else { availability.makeGooglePlayServicesAvailable(activity) .addOnSuccessListener { startLocationFeature() } .addOnFailureListener { showAddressEntryInstead() } } ``` | Situation | What the check tells you | What the app does | |---|---|---| | Play services present and current | `ConnectionResult.SUCCESS` | Use the API | | Installed but outdated or disabled | an error the user can resolve | Show the dialog or call `makeGooglePlayServicesAvailable` | | No Play Store, so no Play services | a missing-service error with no store to install from | Fall back or hide the feature | ## Checking one API instead of the whole app Sometimes you only care about one API. `GoogleApiAvailability.checkApiAvailability(client)` takes one or more API clients (for example a `FusedLocationProviderClient`) and returns a `Task` that fails with an `AvailabilityException` if any of them is unavailable. Google notes that this check is only needed when you want to **disable a feature up front**: you can also just call the API, because its calls fail when the API is unavailable. Today's clients are `GoogleApi`-based objects that are cheap to create; the old `GoogleApiClient` connection object is deprecated, and Google asks apps still using it to migrate. ## Mistakes interviewers listen for - Treating Play services as part of Android. It is a separately installed Google app, absent on devices without the Play Store. - Believing the dependency bundles the implementation. The APK carries a thin client; the work happens in the Play services app. - Treating every non-success code as final. Outdated and disabled are usually fixable by the user in one tap. - Calling the check once at install time. Play services can be disabled or fall behind later, so check where the feature starts.

  • Where does the Maps SDK for Android read its API key, and how do you keep the key out of version control?
    The Maps SDK reads the key from a `<meta-data android:name="com.google.android.geo.API_KEY">` element in the manifest. Google recommends the Secrets Gradle Plugin for Android: put `MAPS_API_KEY=...` in `secrets.properties` at the project root, keep that file out of version control, and reference `${MAPS_API_KEY}` in the manifest. Restrict the key to your app in the Cloud console before release.
  • If every Play services API call fails anyway when the service is missing, why bother checking up front?
    Because the failure arrives late and in the wrong place. A check at the feature's entry point lets you offer the update dialog before the user starts the flow, or hide a button that can never work. Google says `checkApiAvailability` is only needed when you want to disable a feature in advance; otherwise you may call the API and handle its failure.

The client library is a phone extension on your desk; the Play services app is the switchboard that actually connects the call. Plug the extension into an office with no switchboard and dialling gets you nothing, so you check for the switchboard before promising a call.

  • Every Android phone has Google Play services because it ships as part of Android.
  • Adding play-services-location bundles the whole location engine inside the APK.
  • Any result other than ConnectionResult.SUCCESS means the device can never use Play services.
  • Google Play services only gets new versions when the phone receives an OS update.
  • GoogleApiClient.connect() is still the recommended way to reach Play services APIs.

Assumes Google Play services as of 2026-10-10 (play-services-base 18.11.0, play-services-location 21.4.0): automatic updates on Android 7.0 (API level 24) and higher, and GoogleApiClient deprecated in favour of GoogleApi-based clients.