A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/android/reference/com/google/android/gms/common/GoogleApiAvailability below:

GoogleApiAvailability | Google Play services

Skip to main content

Stay organized with collections Save and categorize content based on your preferences.

public class GoogleApiAvailability

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

Summary Public methods @NonNull Task<Void> checkApiAvailability(GoogleApi<Object> api, GoogleApi[] apis)

Checks the availability of the specified APIs.

@NonNull Task<Void> checkApiAvailability(HasApiKey<Object> api, HasApiKey[] apis)

Checks the availability of the specified APIs.

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

Returns a dialog to address the provided errorCode.

@Nullable Dialog getErrorDialog(Fragment fragment, int errorCode, int requestCode)

Returns a dialog to address the provided errorCode.

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

Returns a dialog to address the provided errorCode.

@Nullable Dialog getErrorDialog(
    Fragment fragment,
    int errorCode,
    int requestCode,
    @Nullable DialogInterface.OnCancelListener cancelListener
)

Returns a dialog to address the provided errorCode.

@Nullable PendingIntent getErrorResolutionPendingIntent(
    Context context,
    ConnectionResult result
)

Returns a PendingIntent to address the provided connection failure.

@Nullable PendingIntent getErrorResolutionPendingIntent(
    Context context,
    int errorCode,
    int requestCode
)

Returns a PendingIntent to address the provided errorCode.

final @NonNull String getErrorString(int errorCode)

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

static @NonNull GoogleApiAvailability getInstance()

Returns the singleton instance of GoogleApiAvailability.

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.

@NonNull Task<Void> @MainThread
makeGooglePlayServicesAvailable(Activity activity)

Attempts to make Google Play services available on this device.

void @TargetApi(value = Build.VERSION_CODES.O)
setDefaultNotificationChannelId(
    @NonNull Context context,
    @NonNull String notificationChannelId
)

Overrides the default notification channel for Google Play services availability notifications.

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

Displays a DialogFragment for an error code returned by isGooglePlayServicesAvailable.

boolean showErrorDialogFragment(
    Activity activity,
    int errorCode,
    ActivityResultLauncher<IntentSenderRequest> activityResultLauncher,
    @Nullable DialogInterface.OnCancelListener cancelListener
)

Displays a DialogFragment for an errorCode returned by isGooglePlayServicesAvailable.

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

Displays a DialogFragment for an error code returned by isGooglePlayServicesAvailable.

void showErrorNotification(Context context, int errorCode)

Displays a notification for an error code returned from isGooglePlayServicesAvailable, if it is resolvable by the user.

void showErrorNotification(Context context, ConnectionResult result)

Displays a notification for a connection failure, if it is resolvable by the user.

Constants

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).

Public methods
public @NonNull Task<VoidcheckApiAvailability(GoogleApi<Object> api, GoogleApi[] apis)

Checks the availability of the specified APIs.

If at least one of the APIs is unavailable, the task will fail with a , which can be queried for individual API availability.

public @NonNull Task<VoidcheckApiAvailability(HasApiKey<Object> api, HasApiKey[] apis)

Checks the availability of the specified APIs.

If at least one of the APIs is unavailable, the task will fail with a , which can be queried for individual API availability.

public @Nullable 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. This method follows the startActivityForResult and onActivityResult API pattern. Consider migrating to showErrorDialogFragment as the androidx.activity.result.contract.ActivityResultContracts API is the recommended approach.

Parameters Activity activity

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

int errorCode

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

int requestCode

The number given when calling startActivityForResult.

public @Nullable Dialog getErrorDialog(Fragment fragment, 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. This method follows the startActivityForResult and onActivityResult API pattern. Consider migrating to showErrorDialogFragment as the androidx.activity.result.contract.ActivityResultContracts API is the recommended approach.

Parameters Fragment fragment

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

int errorCode

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

int requestCode

The number given when calling startActivityForResult.

getErrorResolutionPendingIntent

public @Nullable PendingIntent getErrorResolutionPendingIntent(
    Context context,
    ConnectionResult result
)

Returns a PendingIntent to address the provided connection failure.

If hasResolution is true, then getResolution will be returned. Otherwise, the returned PendingIntent will direct the user 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 context

parent context for creating the PendingIntent.

ConnectionResult result

the connection failure. If successful or the error is not resolvable by the user, null is returned.

getErrorResolutionPendingIntent

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

Returns a PendingIntent to address the provided errorCode. It will direct the user 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 context

parent context for creating the PendingIntent.

int errorCode

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

int requestCode

The requestCode given when calling startActivityForResult.

isGooglePlayServicesAvailable

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 int

status code indicating whether there was an error. Can be one of following in : 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 and showing the dialog.

Parameters int errorCode

error code returned by isGooglePlayServicesAvailable, or returned to your application via #onConnectionFailed(ConnectionResult)

Returns boolean

true if the error is resolvable with getErrorDialog

makeGooglePlayServicesAvailable

@MainThread
public @NonNull Task<VoidmakeGooglePlayServicesAvailable(Activity activity)

Attempts to make Google Play services available on this device. If Play Services is already available, the returned Task may complete immediately.

If it is necessary to display UI in order to complete this request (e.g. sending the user to the Google Play store) the passed Activity will be used to display this UI.

It is recommended to call this method from onCreate. If the passed Activity completes before the returned Task completes, the Task will fail with a java.util.concurrent.CancellationException.

This method must be called from the main thread.

Returns @NonNull Task<Void>

A Task. If this Task completes without throwing an exception, Play Services is available on this device.

setDefaultNotificationChannelId

@TargetApi(value = Build.VERSION_CODES.O)
public void setDefaultNotificationChannelId(
    @NonNull Context context,
    @NonNull String notificationChannelId
)

Overrides the default notification channel for Google Play services availability notifications.

It is required to register a NotificationChannel with the notificationChannelId in NotificationManager before calling this method. If the is not registered AND the platform is at least Android O, then a will be thrown.

Parameters @NonNull Context context

The calling context for setting the notification channel.

@NonNull String notificationChannelId

The notification channel for Google Play services availability notifications

public void showErrorNotification(Context context, ConnectionResult result)

Displays a notification for a connection failure, if it is resolvable by the user.

Parameters Context context

The calling context used to display the notification.

ConnectionResult result

The connection failure. If successful or the error is not resolvable by the user, no notification is shown.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-03-17 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-03-17 UTC."],[[["The `GoogleApiAvailability` class helps Android developers ensure Google Play services is available and functioning correctly on user devices."],["It provides methods for checking availability, handling errors (like prompting updates), and displaying user-friendly messages."],["Developers can use it to gracefully manage Google Play services dependencies and enhance the user experience."],["Error handling is facilitated through dialogs or notifications, guiding users to resolve potential issues."],["`showErrorDialogFragment` with `ActivityResultLauncher` is the recommended approach for handling error dialog responses in modern Android development."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4