Android APIs
public class

GoogleApiAvailability

extends Object
java.lang.Object
   ↳ com.google.android.gms.common.GoogleApiAvailability

Class Overview

Helper class for verifying that the Google Play services APK is available and up-to-date on this device.

Summary

Constants
String GOOGLE_PLAY_SERVICES_PACKAGE Package name for Google Play services.
Fields
public static final int GOOGLE_PLAY_SERVICES_VERSION_CODE Google Play services client library version (declared in library's AndroidManifest.xml android:versionCode).
Public Methods
Dialog getErrorDialog(Activity activity, int errorCode, int requestCode, DialogInterface.OnCancelListener cancelListener)
Returns a dialog to address the provided errorCode.
Dialog getErrorDialog(Activity activity, int errorCode, int requestCode)
Returns a dialog to address the provided errorCode.
PendingIntent getErrorResolutionPendingIntent(Context context, int errorCode, int requestCode)
Returns a PendingIntent to address the provided errorCode.
final String getErrorString(int errorCode)
Returns a human-readable string of the error code returned from isGooglePlayServicesAvailable(Context).
static GoogleApiAvailability getInstance()
Returns the singleton instance of GoogleApiAvailability.
String getOpenSourceSoftwareLicenseInfo(Context context)
Returns the open source software license information for the Google Play services application, or null if Google Play services is not available on this device.
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.
final boolean isUserResolvableError(int errorCode)
Determines whether an error can be resolved via user action.
boolean showErrorDialogFragment(Activity activity, int errorCode, int requestCode, DialogInterface.OnCancelListener cancelListener)
Displays a DialogFragment for an error code returned by isGooglePlayServicesAvailable(Context).
boolean showErrorDialogFragment(Activity activity, int errorCode, int requestCode)
Displays a DialogFragment for an error code returned by isGooglePlayServicesAvailable(Context).
void showErrorNotification(Context context, int errorCode)
Displays a notification relevant to the provided error code.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String GOOGLE_PLAY_SERVICES_PACKAGE

Package name for Google Play services.

Constant Value: "com.google.android.gms"

Fields

public static final int GOOGLE_PLAY_SERVICES_VERSION_CODE

Google Play services client library version (declared in library's AndroidManifest.xml android:versionCode).

Public Methods

public Dialog getErrorDialog (Activity activity, int errorCode, int requestCode, DialogInterface.OnCancelListener cancelListener)

Returns a dialog to address the provided errorCode. The returned dialog displays a localized message about the error and upon user confirmation (by tapping on dialog) will direct them to the Play Store if Google Play services is out of date or missing, or to system settings if Google Play services is disabled on the device.

Parameters
activity parent activity for creating the dialog, also used for identifying language to display dialog in.
errorCode error code returned by isGooglePlayServicesAvailable(Context) call. If errorCode is SUCCESS then null is returned.
requestCode The requestCode given when calling startActivityForResult.
cancelListener The DialogInterface.OnCancelListener to invoke if the dialog is canceled.

public Dialog getErrorDialog (Activity activity, int errorCode, int requestCode)

Returns a dialog to address the provided errorCode. The returned dialog displays a localized message about the error and upon user confirmation (by tapping on dialog) will direct them to the Play Store if Google Play services is out of date or missing, or to system settings if Google Play services is disabled on the device.

Parameters
activity parent activity for creating the dialog, also used for identifying language to display dialog in.
errorCode error code returned by isGooglePlayServicesAvailable(Context) call. If errorCode is SUCCESS then null is returned.
requestCode The requestCode given when calling startActivityForResult.

public PendingIntent getErrorResolutionPendingIntent (Context context, int errorCode, int requestCode)

Returns a PendingIntent to address the provided errorCode. It will direct them to either the Play Store if Google Play services is out of date or missing, or system settings if Google Play services is disabled on the device.

Parameters
context parent context for creating the PendingIntent.
errorCode error code returned by isGooglePlayServicesAvailable(Context) call. If errorCode is SUCCESS then null is returned.
requestCode The requestCode given when calling startActivityForResult.

public final String getErrorString (int errorCode)

Returns a human-readable string of the error code returned from isGooglePlayServicesAvailable(Context).

public static GoogleApiAvailability getInstance ()

Returns the singleton instance of GoogleApiAvailability.

public String getOpenSourceSoftwareLicenseInfo (Context context)

Returns the open source software license information for the Google Play services application, or null if Google Play services is not available on this device.

public 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_UPDATING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID

public final boolean isUserResolvableError (int errorCode)

Determines whether an error can be resolved via user action. If true, proceed by calling getErrorDialog(Activity, int, int) and showing the dialog.

Parameters
errorCode error code returned by isGooglePlayServicesAvailable(Context), or returned to your application via onConnectionFailed(ConnectionResult)
Returns

public boolean showErrorDialogFragment (Activity activity, int errorCode, int requestCode, DialogInterface.OnCancelListener cancelListener)

Displays a DialogFragment for an error code returned by isGooglePlayServicesAvailable(Context).

Parameters
activity parent activity for creating the dialog, also used for identifying language to display dialog in.
errorCode error code returned by isGooglePlayServicesAvailable(Context) call. If errorCode is SUCCESS then this does nothing
requestCode The requestCode given when calling startActivityForResult.
cancelListener The DialogInterface.OnCancelListener to invoke if the dialog is canceled.
Returns
  • true if the dialog is shown, false otherwise.
Throws
RuntimeException if API level is below 11 and activity is not a FragmentActivity.

public boolean showErrorDialogFragment (Activity activity, int errorCode, int requestCode)

Displays a DialogFragment for an error code returned by isGooglePlayServicesAvailable(Context).

Parameters
activity parent activity for creating the dialog, also used for identifying language to display dialog in.
errorCode error code returned by isGooglePlayServicesAvailable(Context) call. If errorCode is SUCCESS then this does nothing.
requestCode The requestCode given when calling startActivityForResult.
Returns
  • true if the dialog is shown, false otherwise
Throws
RuntimeException if API level is below 11 and activity is not a FragmentActivity.

public void showErrorNotification (Context context, int errorCode)

Displays a notification relevant to the provided error code. This method is similar to getErrorDialog(android.app.Activity, int, int), but is provided for background tasks that cannot or should not display dialogs.

Parameters
context used for identifying language to display dialog in as well as accessing the NotificationManager.
errorCode error code returned by isGooglePlayServicesAvailable(Context) call. If errorCode is SUCCESS then null is returned.