GooglePlayServicesUtil

public final class GooglePlayServicesUtil 

Utility class for verifying that the Google Play services APK is available and up-to-date on this device. The same checks are performed if one uses or to connect to the service.

Summary

Constants

static final String
GMS_ERROR_DIALOG = "GooglePlayServicesErrorDialog"
static final String
GOOGLE_PLAY_SERVICES_PACKAGE = "com.google.android.gms"

This field is deprecated.

Use GOOGLE_PLAY_SERVICES_PACKAGE instead.

static final String
GOOGLE_PLAY_SERVICES_PACKAGE = "com.google.android.gms"

This field is deprecated.

Use GOOGLE_PLAY_SERVICES_PACKAGE instead.

static final int

This field is deprecated.

Use GOOGLE_PLAY_SERVICES_VERSION_CODE instead.

static final int

This field is deprecated.

Use GOOGLE_PLAY_SERVICES_VERSION_CODE instead.

static final String
GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending"

Package name for Google Play Store.

static final String
GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending"

See GOOGLE_PLAY_STORE_PACKAGE .

Public methods

static @ Nullable Dialog
getErrorDialog (int errorCode,  Activity  activity, int requestCode)

This method is deprecated.

Use getErrorDialog instead.

static @ Nullable Dialog
getErrorDialog (
    int errorCode,
Activity  activity,
    int requestCode,
    @ Nullable DialogInterface.OnCancelListener  cancelListener
)

This method is deprecated.

Use getErrorDialog instead.

static PendingIntent
getErrorPendingIntent (int errorCode,  Context  context, int requestCode)

This method is deprecated.

Use getErrorResolutionPendingIntent instead.

static String
getErrorString (int errorCode)

This method is deprecated.

Use getErrorString instead.

static @ Nullable String
@ SuppressViolation (value = "catch_specific_exceptions")
getOpenSourceSoftwareLicenseInfo ( Context  context)

This method is deprecated.

This license information is displayed in Settings >Google >Open Source on any device running Google Play services.

static Context
getRemoteContext ( Context  context)

This gets the Context object of the Buddy APK.

static Resources
getRemoteResource ( Context  context)

This gets the Resources object of the Buddy APK.

static int

This method is deprecated.

Use isGooglePlayServicesAvailable instead.

static boolean
isUserRecoverableError (int errorCode)

This method is deprecated.

Use isUserResolvableError instead.

static boolean

Gets the current opt-in state of using a background thread executor.

static boolean
@ CanIgnoreReturnValue
showErrorDialogFragment (
    int errorCode,
Activity  activity,
    int requestCode
)

This method is deprecated.

Use showErrorDialogFragment instead.

static boolean
@ InlineMe (replacement = "GooglePlayServicesUtil.showErrorDialogFragment(errorCode, activity, (Fragment) null," + " requestCode, cancelListener)", imports = [""androidx.fragment.app.Fragment"", ""com.google.android.gms.common.GooglePlayServicesUtil""])
@ CanIgnoreReturnValue
showErrorDialogFragment (
    int errorCode,
Activity  activity,
    int requestCode,
    @ Nullable DialogInterface.OnCancelListener  cancelListener
)

This method is deprecated.

Use showErrorDialogFragment instead.

static boolean
@ CanIgnoreReturnValue
showErrorDialogFragment (
    int errorCode,
Activity  activity,
    @ Nullable Fragment  fragment,
    int requestCode,
    @ Nullable DialogInterface.OnCancelListener  cancelListener
)
static void
showErrorNotification (int errorCode,  Context  context)

This method is deprecated.

Use showErrorNotification instead.

static boolean

Requests to use a background thread executor for callbacks on ServiceConnection for all APIs that connect to Google Play services on API level 29+.

static void

Request to use a background thread for the internal message queue of Google Play services APIs.

Constants

GMS_ERROR_DIALOG

public static final  String 
 GMS_ERROR_DIALOG 
= "GooglePlayServicesErrorDialog"

GOOGLE_PLAY_SERVICES_PACKAGE

public static final  String 
 GOOGLE_PLAY_SERVICES_PACKAGE 
= "com.google.android.gms"

Package name for Google Play services.

GOOGLE_PLAY_SERVICES_PACKAGE

public static final  String 
 GOOGLE_PLAY_SERVICES_PACKAGE 
= "com.google.android.gms"

GOOGLE_PLAY_SERVICES_VERSION_CODE

public static final int  GOOGLE_PLAY_SERVICES_VERSION_CODE 

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

GOOGLE_PLAY_SERVICES_VERSION_CODE

public static final int  GOOGLE_PLAY_SERVICES_VERSION_CODE 

GOOGLE_PLAY_STORE_PACKAGE

public static final  String 
 GOOGLE_PLAY_STORE_PACKAGE 
= "com.android.vending"

Package name for Google Play Store.

GOOGLE_PLAY_STORE_PACKAGE

public static final  String 
 GOOGLE_PLAY_STORE_PACKAGE 
= "com.android.vending"

See GOOGLE_PLAY_STORE_PACKAGE .

Public methods

getErrorDialog

public static @ Nullable 
 Dialog 
   getErrorDialog 
 
 
(int errorCode,  Activity 
 activity, 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
int errorCode

error code returned by isGooglePlayServicesAvailable call. If errorCode is SUCCESS then null is returned.

Activity  activity

parent activity for creating the dialog, also used for identifying language to display dialog in.

int requestCode

The requestCode given when calling startActivityForResult.

getErrorDialog

public static @ Nullable 
 Dialog 
   getErrorDialog 
 
 
(
    int errorCode,
Activity  activity,
    int requestCode,
    @ Nullable 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
int errorCode

error code returned by isGooglePlayServicesAvailable call. If errorCode is SUCCESS then null is returned.

Activity  activity

parent activity for creating the dialog, also used for identifying language to display dialog in.

int requestCode

The requestCode given when calling startActivityForResult.

@ Nullable DialogInterface.OnCancelListener  cancelListener

The DialogInterface.OnCancelListener to invoke if the dialog is canceled.

getErrorPendingIntent

public static  PendingIntent 
   getErrorPendingIntent 
 
 
(int errorCode,  Context 
 context, int requestCode)

Returns a PendingIntent to address the provided errorCode. It will direct them to one of the following places 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
int errorCode

error code returned by isGooglePlayServicesAvailable call. If errorCode is SUCCESS then null is returned.

Context  context

parent context for creating the PendingIntent.

int requestCode

The requestCode given when calling startActivityForResult.

getErrorString

public static  String 
   getErrorString 
 
 
(int errorCode)

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

getOpenSourceSoftwareLicenseInfo

@ SuppressViolation 
(value = "catch_specific_exceptions")
public static @ Nullable String getOpenSourceSoftwareLicenseInfo ( Context  context)

getRemoteContext

public static  Context 
 getRemoteContext 
( Context 
 context)

This gets the Context object of the Buddy APK. This loads the Buddy APK code from the Buddy APK into memory. This returned context can be used to create classes and obtain resources defined in the Buddy APK.

Returns
Context

The Context object of the Buddy APK or null if the Buddy APK is not installed on the device.

getRemoteResource

public static  Resources 
 getRemoteResource 
( Context 
 context)

This gets the Resources object of the Buddy APK.

Returns
Resources

The Resources object of the Buddy APK or null if the Buddy APK is not installed on the device.

isGooglePlayServicesAvailable

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
int

status code indicating whether there was an error. Can be one of following in : SUCCESS, SERVICE_MISSING, SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID

isUserRecoverableError

public static boolean    isUserRecoverableError 
 
 
(int errorCode)

Determines whether an error is user-recoverable. If true, proceed by calling getErrorDialog and showing the dialog.

Parameters
int errorCode

error code returned by isGooglePlayServicesAvailable , or returned to your application via GoogleApiClient.OnConnectionFailedListener#onConnectionFailed

Returns
boolean

true if the error is recoverable with getErrorDialog

isUsingBackgroundThreadExecutorForBindService

public static boolean  isUsingBackgroundThreadExecutorForBindService 
()

Gets the current opt-in state of using a background thread executor.

Returns
boolean

true if the app has opted in to use a background thread executor using useBackgroundThreadExecutorForBindService for callbacks on for all APIs that connect to Google Play services on API level 29+.

showErrorDialogFragment

@ CanIgnoreReturnValue 

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

Display a DialogFragment for an error code returned by isGooglePlayServicesAvailable .

Parameters
int errorCode

error code returned by isGooglePlayServicesAvailable call. If errorCode is SUCCESS then this does nothing.

Activity  activity

parent activity for creating the dialog, also used for identifying language to display dialog in.

int requestCode

The requestCode given when calling startActivityForResult.

Returns
boolean

true if the dialog is shown, false otherwise

Throws
java.lang.RuntimeException

if API level is below 11 and activity is not a .

showErrorDialogFragment

@ InlineMe 
(replacement = "GooglePlayServicesUtil.showErrorDialogFragment(errorCode, activity, (Fragment) null,"
              + " requestCode, cancelListener)", imports = [""androidx.fragment.app.Fragment"", ""com.google.android.gms.common.GooglePlayServicesUtil""])
@ CanIgnoreReturnValue
public static boolean  showErrorDialogFragment (
    int errorCode,
Activity  activity,
    int requestCode,
    @ Nullable DialogInterface.OnCancelListener  cancelListener
)

Display a DialogFragment for an error code returned by isGooglePlayServicesAvailable .

Parameters
int errorCode

error code returned by isGooglePlayServicesAvailable call. If errorCode is SUCCESS then this does nothing

Activity  activity

parent activity for creating the dialog, also used for identifying language to display dialog in.

int requestCode

The requestCode given when calling startActivityForResult.

@ Nullable DialogInterface.OnCancelListener  cancelListener

The DialogInterface.OnCancelListener to invoke if the dialog is canceled.

Returns
boolean

true if the dialog is shown, false otherwise.

Throws
java.lang.RuntimeException

if API level is below 11 and activity is not a .

showErrorDialogFragment

@ CanIgnoreReturnValue 

public static boolean  showErrorDialogFragment (
    int errorCode,
Activity  activity,
    @ Nullable Fragment  fragment,
    int requestCode,
    @ Nullable DialogInterface.OnCancelListener  cancelListener
)

showErrorNotification

public static void    showErrorNotification 
 
 
(int errorCode,  Context 
 context)

Displays a notification relevant to the provided error code. This method is similar to getErrorDialog , but is provided for background tasks that cannot or shouldn't display dialogs.

Parameters
int errorCode

error code returned by isGooglePlayServicesAvailable call. If errorCode is SUCCESS then null is returned.

Context  context

used for identifying language to display dialog in as well as accessing the android.app.NotificationManager .

useBackgroundThreadExecutorForBindService

@ CanIgnoreReturnValue 

public static boolean  useBackgroundThreadExecutorForBindService ()

Requests to use a background thread executor for callbacks on ServiceConnection for all APIs that connect to Google Play services on API level 29+.

This method has to be called before the internal initialization of Google Play services APIs and before any Google Play services API is called, ideally during the initialization of your app.

Use with useBackgroundThreadForConnectionCallback to achieve optimal background thread utilization in Google Play services APIs.

Returns
boolean

true if the request is received before the internal initialization of Google Play services APIs and successful.

useBackgroundThreadForConnectionCallback

public static void  useBackgroundThreadForConnectionCallback 
()

Request to use a background thread for the internal message queue of Google Play services APIs.

Use with useBackgroundThreadExecutorForBindService to achieve optimal background thread utilization in Google Play services APIs.

Create a Mobile Website
View Site in Mobile | Classic
Share by: