GooglePlayServicesUtil

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

const String!
GMS_ERROR_DIALOG = "GooglePlayServicesErrorDialog"
const String!
GOOGLE_PLAY_SERVICES_PACKAGE = "com.google.android.gms"

This property is deprecated.

Use GOOGLE_PLAY_SERVICES_PACKAGE instead.

const String!
GOOGLE_PLAY_SERVICES_PACKAGE = "com.google.android.gms"

This property is deprecated.

Use GOOGLE_PLAY_SERVICES_PACKAGE instead.

const Int

This property is deprecated.

Use GOOGLE_PLAY_SERVICES_VERSION_CODE instead.

const Int

This property is deprecated.

Use GOOGLE_PLAY_SERVICES_VERSION_CODE instead.

const String!
GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending"

Package name for Google Play Store.

const String!
GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending"

See GOOGLE_PLAY_STORE_PACKAGE.

Public functions

java-static Dialog?
getErrorDialog(errorCode: Int, activity: Activity!, requestCode: Int)

This function is deprecated.

Use getErrorDialog instead.

java-static Dialog?
getErrorDialog(
    errorCode: Int,
    activity: Activity!,
    requestCode: Int,
    cancelListener: DialogInterface.OnCancelListener?
)

This function is deprecated.

Use getErrorDialog instead.

java-static PendingIntent!
getErrorPendingIntent(errorCode: Int, context: Context!, requestCode: Int)

This function is deprecated.

Use getErrorResolutionPendingIntent instead.

java-static String!
getErrorString(errorCode: Int)

This function is deprecated.

Use getErrorString instead.

java-static String?
@SuppressViolation(value = "catch_specific_exceptions")
getOpenSourceSoftwareLicenseInfo(context: Context!)

This function is deprecated.

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

java-static Context!

This gets the Context object of the Buddy APK.

java-static Resources!

This gets the Resources object of the Buddy APK.

java-static Int

This function is deprecated.

Use isGooglePlayServicesAvailable instead.

java-static Boolean

This function is deprecated.

Use isUserResolvableError instead.

java-static Boolean

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

java-static Boolean
showErrorDialogFragment(
    errorCode: Int,
    activity: Activity!,
    requestCode: Int
)

This function is deprecated.

Use showErrorDialogFragment instead.

java-static Boolean
@InlineMe(replacement = "GooglePlayServicesUtil.showErrorDialogFragment(errorCode, activity, (Fragment) null," + " requestCode, cancelListener)", imports = [""androidx.fragment.app.Fragment"", ""com.google.android.gms.common.GooglePlayServicesUtil""])
showErrorDialogFragment(
    errorCode: Int,
    activity: Activity!,
    requestCode: Int,
    cancelListener: DialogInterface.OnCancelListener?
)

This function is deprecated.

Use showErrorDialogFragment instead.

java-static Boolean
showErrorDialogFragment(
    errorCode: Int,
    activity: Activity!,
    fragment: Fragment?,
    requestCode: Int,
    cancelListener: DialogInterface.OnCancelListener?
)
java-static Unit
showErrorNotification(errorCode: Int, context: Context!)

This function is deprecated.

Use showErrorNotification instead.

java-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+.

java-static Unit

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

Constants

GMS_ERROR_DIALOG

const val GMS_ERROR_DIALOG = "GooglePlayServicesErrorDialog": String!

GOOGLE_PLAY_SERVICES_PACKAGE

const val GOOGLE_PLAY_SERVICES_PACKAGE = "com.google.android.gms": String!

Package name for Google Play services.

GOOGLE_PLAY_SERVICES_PACKAGE

const val GOOGLE_PLAY_SERVICES_PACKAGE = "com.google.android.gms": String!

GOOGLE_PLAY_SERVICES_VERSION_CODE

const val GOOGLE_PLAY_SERVICES_VERSION_CODEInt

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

GOOGLE_PLAY_SERVICES_VERSION_CODE

const val GOOGLE_PLAY_SERVICES_VERSION_CODEInt

GOOGLE_PLAY_STORE_PACKAGE

const val GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending": String!

Package name for Google Play Store.

GOOGLE_PLAY_STORE_PACKAGE

const val GOOGLE_PLAY_STORE_PACKAGE = "com.android.vending": String!

See GOOGLE_PLAY_STORE_PACKAGE.

Public functions

getErrorDialog

java-static fun getErrorDialog(errorCode: Int, activity: Activity!, requestCode: Int): Dialog?

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
errorCode: Int

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.

requestCode: Int

The requestCode given when calling startActivityForResult.

getErrorDialog

java-static fun getErrorDialog(
    errorCode: Int,
    activity: Activity!,
    requestCode: Int,
    cancelListener: DialogInterface.OnCancelListener?
): Dialog?

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
errorCode: Int

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.

requestCode: Int

The requestCode given when calling startActivityForResult.

cancelListener: DialogInterface.OnCancelListener?

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

getErrorPendingIntent

java-static fun getErrorPendingIntent(errorCode: Int, context: Context!, requestCode: Int): PendingIntent!

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
errorCode: Int

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

context: Context!

parent context for creating the PendingIntent.

requestCode: Int

The requestCode given when calling startActivityForResult.

getErrorString

java-static fun getErrorString(errorCode: Int): String!

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

getOpenSourceSoftwareLicenseInfo

@SuppressViolation(value = "catch_specific_exceptions")
java-static fun getOpenSourceSoftwareLicenseInfo(context: Context!): String?

getRemoteContext

java-static fun getRemoteContext(context: 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

java-static fun getRemoteResource(context: Context!): Resources!

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

java-static fun isGooglePlayServicesAvailable(context: Context!): Int

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

java-static fun isUserRecoverableError(errorCode: Int): Boolean

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

Parameters
errorCode: Int

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

java-static fun isUsingBackgroundThreadExecutorForBindService(): Boolean

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

java-static fun showErrorDialogFragment(
    errorCode: Int,
    activity: Activity!,
    requestCode: Int
): Boolean

Display a DialogFragment for an error code returned by isGooglePlayServicesAvailable.

Parameters
errorCode: Int

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.

requestCode: Int

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""])
java-static fun showErrorDialogFragment(
    errorCode: Int,
    activity: Activity!,
    requestCode: Int,
    cancelListener: DialogInterface.OnCancelListener?
): Boolean

Display a DialogFragment for an error code returned by isGooglePlayServicesAvailable.

Parameters
errorCode: Int

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.

requestCode: Int

The requestCode given when calling startActivityForResult.

cancelListener: DialogInterface.OnCancelListener?

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

java-static fun showErrorDialogFragment(
    errorCode: Int,
    activity: Activity!,
    fragment: Fragment?,
    requestCode: Int,
    cancelListener: DialogInterface.OnCancelListener?
): Boolean

showErrorNotification

java-static fun showErrorNotification(errorCode: Int, context: Context!): Unit

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
errorCode: Int

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
java-static fun useBackgroundThreadExecutorForBindService(): 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+.

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

java-static fun useBackgroundThreadForConnectionCallback(): Unit

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.