Games

public final class Games extends Object

Main entry point for the Games APIs. This class provides APIs and interfaces to access the Google Play game services functionality.

To use the service, get a GamesClient by calling getGamesClient(Activity, GoogleSignInAccount) or getGamesClient(Context, GoogleSignInAccount). Then request an activation information by calling getActivationHint(). If retrieved Bundle is not null it can contain the following keys:

For more information, see the "Getting Started" guide available at //developers.google.com/games/services/android/quickstart.

Nested Class Summary

class Games.GamesOptions This class was deprecated. Use setViewForPopups(View) and setGravityForPopups(int) instead.  

Constant Summary

String EXTRA_PLAYER_IDS Used to return a list of player IDs.
String EXTRA_STATUS Used to return a Status object from activities.

Field Summary

public static final Api<Games.GamesOptions> API This field was deprecated. This is no longer necessary to provide.
public static final Achievements Achievements This field was deprecated. Use getAchievementsClient(Activity, GoogleSignInAccount) or getAchievementsClient(Context, GoogleSignInAccount) instead.
public static final Events Events This field was deprecated. Use getEventsClient(Activity, GoogleSignInAccount) or getEventsClient(Context, GoogleSignInAccount) instead.
public static final GamesMetadata GamesMetadata This field was deprecated. Use getGamesMetadataClient(Activity, GoogleSignInAccount) or getGamesMetadataClient(Context, GoogleSignInAccount) instead.
public static final Invitations Invitations This field was deprecated. Use getInvitationsClient(Activity, GoogleSignInAccount) or getInvitationsClient(Context, GoogleSignInAccount) instead.
public static final Leaderboards Leaderboards This field was deprecated. Use getLeaderboardsClient(Activity, GoogleSignInAccount) or getLeaderboardsClient(Context, GoogleSignInAccount) instead.
public static final Notifications Notifications This field was deprecated. Use getNotificationsClient(Activity, GoogleSignInAccount) or getNotificationsClient(Context, GoogleSignInAccount) instead.
public static final Players Players This field was deprecated. Use getPlayersClient(Activity, GoogleSignInAccount) or getPlayersClient(Context, GoogleSignInAccount) instead.
public static final Quests Quests This field was deprecated. The Google Play Games quests service will be deprecated as of March 2018. Do not use the Google Play Games quests service in new apps. See the deprecation announcement blog post for more details.
public static final RealTimeMultiplayer RealTimeMultiplayer This field was deprecated. Use getRealTimeMultiplayerClient(Activity, GoogleSignInAccount) or getRealTimeMultiplayerClient(Context, GoogleSignInAccount) instead.
public static final Requests Requests This field was deprecated. The Google Play Games request service will be deprecated as of March 2018. Do not use the Google Play Games request service in new apps. See the deprecation announcement blog post for more details.
public static final Scope SCOPE_GAMES Scope for accessing data from Google Play Games.
public static final Scope SCOPE_GAMES_LITE Scope for accessing data from Google Play Games without providing any user information.
public static final Snapshots Snapshots This field was deprecated. Use getSnapshotsClient(Activity, GoogleSignInAccount) or getSnapshotsClient(Context, GoogleSignInAccount) instead.
public static final Stats Stats This field was deprecated. Use getPlayerStatsClient(Activity, GoogleSignInAccount) or getPlayerStatsClient(Context, GoogleSignInAccount) instead.
public static final TurnBasedMultiplayer TurnBasedMultiplayer This field was deprecated. Use getTurnBasedMultiplayerClient(Activity, GoogleSignInAccount) or getTurnBasedMultiplayerClient(Context, GoogleSignInAccount) instead.
public static final Videos Videos This field was deprecated. Use getVideosClient(Activity, GoogleSignInAccount) or getVideosClient(Context, GoogleSignInAccount) instead.

Public Method Summary

static AchievementsClient
getAchievementsClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of AchievementsClient for use in an Activity.
static AchievementsClient
getAchievementsClient(Context context, GoogleSignInAccount account)
Returns a new instance of AchievementsClient for use in a Context.
static String
getAppId(GoogleApiClient apiClient)
This method was deprecated. Use getAppId() instead.
static String
getCurrentAccountName(GoogleApiClient apiClient)
This method was deprecated. Use getCurrentAccountName() instead.
static EventsClient
getEventsClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of EventsClient for use in an Activity.
static EventsClient
getEventsClient(Context context, GoogleSignInAccount account)
Returns a new instance of EventsClient for use in a Context.
static GamesClient
getGamesClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of GamesClient for use in an Activity.
static GamesClient
getGamesClient(Context context, GoogleSignInAccount account)
Returns a new instance of GamesClient for use in a Context.
static GamesMetadataClient
getGamesMetadataClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of GamesMetadataClient for use in an Activity.
static GamesMetadataClient
getGamesMetadataClient(Context context, GoogleSignInAccount account)
Returns a new instance of GamesMetadataClient for use in a Context.
static InvitationsClient
getInvitationsClient(Context context, GoogleSignInAccount account)
Returns a new instance of InvitationsClient for use in a Context.
static InvitationsClient
getInvitationsClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of InvitationsClient for use in an Activity.
static LeaderboardsClient
getLeaderboardsClient(Context context, GoogleSignInAccount account)
Returns a new instance of LeaderboardsClient for use in a Context.
static LeaderboardsClient
getLeaderboardsClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of LeaderboardsClient for use in an Activity.
static NotificationsClient
getNotificationsClient(Context context, GoogleSignInAccount account)
Returns a new instance of NotificationsClient for use in a Context.
static NotificationsClient
getNotificationsClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of NotificationsClient for use in an Activity.
static PlayerStatsClient
getPlayerStatsClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of PlayerStatsClient for use in an Activity.
static PlayerStatsClient
getPlayerStatsClient(Context context, GoogleSignInAccount account)
Returns a new instance of PlayerStatsClient for use in a Context.
static PlayersClient
getPlayersClient(Context context, GoogleSignInAccount account)
Returns a new instance of PlayersClient for use in a Context.
static PlayersClient
getPlayersClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of PlayersClient for use in an Activity.
static RealTimeMultiplayerClient
getRealTimeMultiplayerClient(Context context, GoogleSignInAccount account)
Returns a new instance of RealTimeMultiplayerClient for use in a Context.
static RealTimeMultiplayerClient
getRealTimeMultiplayerClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of RealTimeMultiplayerClient for use in an Activity.
static int
getSdkVariant(GoogleApiClient apiClient)
This method was deprecated. Use GamesClient#getSdkVariant() instead.
static Intent
getSettingsIntent(GoogleApiClient apiClient)
This method was deprecated. Use getSettingsIntent() instead.
static SnapshotsClient
getSnapshotsClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of SnapshotsClient for use in an Activity.
static SnapshotsClient
getSnapshotsClient(Context context, GoogleSignInAccount account)
Returns a new instance of SnapshotsClient for use in a Context.
static TurnBasedMultiplayerClient
getTurnBasedMultiplayerClient(Context context, GoogleSignInAccount account)
Returns a new instance of TurnBasedMultiplayerClient for use in a Context.
static TurnBasedMultiplayerClient
getTurnBasedMultiplayerClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of TurnBasedMultiplayerClient for use in an Activity.
static VideosClient
getVideosClient(Context context, GoogleSignInAccount account)
Returns a new instance of VideosClient for use in a Context.
static VideosClient
getVideosClient(Activity activity, GoogleSignInAccount account)
Returns a new instance of VideosClient for use in an Activity.
static void
setGravityForPopups(GoogleApiClient apiClient, int gravity)
This method was deprecated. Use setGravityForPopups(int) instead.
static void
setViewForPopups(GoogleApiClient apiClient, View gamesContentView)
This method was deprecated. Use setViewForPopups(View) instead.
static PendingResult<Status>
signOut(GoogleApiClient apiClient)
This method was deprecated. Use signOut() instead.

Inherited Method Summary

Constants

public static final String EXTRA_PLAYER_IDS

Used to return a list of player IDs. Retrieve with getStringArrayListExtra(String).

Also used to pass in a list of player IDs for preselecting players. Set with putStringArrayListExtra(String, java.util.ArrayList).

See getSelectOpponentsIntent(int, int), getSelectOpponentsIntent(int, int)

Constant Value: "players"

public static final String EXTRA_STATUS

Used to return a Status object from activities. Retrieve with getParcelableExtra(String).

Constant Value: "status"

Fields

public static final Api<Games.GamesOptions> API

This field was deprecated.
This is no longer necessary to provide.

Token to pass to addApi(Api ) to enable the Games features.

To configure additional Games options, provide a Games.GamesOptions object to addApi(Api ).

public static final Achievements Achievements

This field was deprecated.
Use getAchievementsClient(Activity, GoogleSignInAccount) or getAchievementsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with achievements.

public static final Events Events

This field was deprecated.
Use getEventsClient(Activity, GoogleSignInAccount) or getEventsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with events.

public static final GamesMetadata GamesMetadata

This field was deprecated.
Use getGamesMetadataClient(Activity, GoogleSignInAccount) or getGamesMetadataClient(Context, GoogleSignInAccount) instead.

Methods for interacting with game metadata.

public static final Invitations Invitations

This field was deprecated.
Use getInvitationsClient(Activity, GoogleSignInAccount) or getInvitationsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with invitations.

public static final Leaderboards Leaderboards

This field was deprecated.
Use getLeaderboardsClient(Activity, GoogleSignInAccount) or getLeaderboardsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with leaderboard data.

public static final Notifications Notifications

This field was deprecated.
Use getNotificationsClient(Activity, GoogleSignInAccount) or getNotificationsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with notifications.

public static final Players Players

This field was deprecated.
Use getPlayersClient(Activity, GoogleSignInAccount) or getPlayersClient(Context, GoogleSignInAccount) instead.

Methods for interacting with players.

public static final Quests Quests

This field was deprecated.
The Google Play Games quests service will be deprecated as of March 2018. Do not use the Google Play Games quests service in new apps. See the deprecation announcement blog post for more details.

Methods for interacting with quests.

public static final RealTimeMultiplayer RealTimeMultiplayer

This field was deprecated.
Use getRealTimeMultiplayerClient(Activity, GoogleSignInAccount) or getRealTimeMultiplayerClient(Context, GoogleSignInAccount) instead.

Methods for interacting with real-time multiplayer games.

public static final Requests Requests

This field was deprecated.
The Google Play Games request service will be deprecated as of March 2018. Do not use the Google Play Games request service in new apps. See the deprecation announcement blog post for more details.

Methods for interacting with requests.

public static final Scope SCOPE_GAMES

Scope for accessing data from Google Play Games.

public static final Scope SCOPE_GAMES_LITE

Scope for accessing data from Google Play Games without providing any user information.

public static final Snapshots Snapshots

This field was deprecated.
Use getSnapshotsClient(Activity, GoogleSignInAccount) or getSnapshotsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with snapshots.

public static final Stats Stats

This field was deprecated.
Use getPlayerStatsClient(Activity, GoogleSignInAccount) or getPlayerStatsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with game and player stats.

public static final TurnBasedMultiplayer TurnBasedMultiplayer

This field was deprecated.
Use getTurnBasedMultiplayerClient(Activity, GoogleSignInAccount) or getTurnBasedMultiplayerClient(Context, GoogleSignInAccount) instead.

Methods for interacting with turn-based multiplayer games.

public static final Videos Videos

This field was deprecated.
Use getVideosClient(Activity, GoogleSignInAccount) or getVideosClient(Context, GoogleSignInAccount) instead.

Methods for interacting with video recording.

Public Methods

public static AchievementsClient getAchievementsClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of AchievementsClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static AchievementsClient getAchievementsClient (Context context, GoogleSignInAccount account)

Returns a new instance of AchievementsClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static String getAppId (GoogleApiClient apiClient)

This method was deprecated.
Use getAppId() instead.

Get the application ID linked to this client instance.

Required API: API
Required Scopes: SCOPE_GAMES

Parameters
apiClient The GoogleApiClient to service the call.
Returns
  • The application ID linked to this client instance.

public static String getCurrentAccountName (GoogleApiClient apiClient)

This method was deprecated.
Use getCurrentAccountName() instead.

Get the name of the currently selected account. This is the account the user has chosen to use for Google Play Games.

Note that the GoogleApiClient must be connected to call this API, and your app must have <uses-permission android:name="android.permission.GET_ACCOUNTS" /> declared in your manifest in order to use this method.

Required API: API
Required Scopes: SCOPE_GAMES

Parameters
apiClient The GoogleApiClient to service the call.
Returns
  • Account name for the currently selected account. May be null if an error occurred while communicating with the games service.
Throws
SecurityException If your app doesn't have the GET_ACCOUNTS permission.

public static EventsClient getEventsClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of EventsClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static EventsClient getEventsClient (Context context, GoogleSignInAccount account)

Returns a new instance of EventsClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static GamesClient getGamesClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of GamesClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static GamesClient getGamesClient (Context context, GoogleSignInAccount account)

Returns a new instance of GamesClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static GamesMetadataClient getGamesMetadataClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of GamesMetadataClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static GamesMetadataClient getGamesMetadataClient (Context context, GoogleSignInAccount account)

Returns a new instance of GamesMetadataClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static InvitationsClient getInvitationsClient (Context context, GoogleSignInAccount account)

Returns a new instance of InvitationsClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static InvitationsClient getInvitationsClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of InvitationsClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static LeaderboardsClient getLeaderboardsClient (Context context, GoogleSignInAccount account)

Returns a new instance of LeaderboardsClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static LeaderboardsClient getLeaderboardsClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of LeaderboardsClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static NotificationsClient getNotificationsClient (Context context, GoogleSignInAccount account)

Returns a new instance of NotificationsClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static NotificationsClient getNotificationsClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of NotificationsClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static PlayerStatsClient getPlayerStatsClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of PlayerStatsClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static PlayerStatsClient getPlayerStatsClient (Context context, GoogleSignInAccount account)

Returns a new instance of PlayerStatsClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static PlayersClient getPlayersClient (Context context, GoogleSignInAccount account)

Returns a new instance of PlayersClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static PlayersClient getPlayersClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of PlayersClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static RealTimeMultiplayerClient getRealTimeMultiplayerClient (Context context, GoogleSignInAccount account)

Returns a new instance of RealTimeMultiplayerClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static RealTimeMultiplayerClient getRealTimeMultiplayerClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of RealTimeMultiplayerClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static int getSdkVariant (GoogleApiClient apiClient)

This method was deprecated.
Use GamesClient#getSdkVariant() instead.

public static Intent getSettingsIntent (GoogleApiClient apiClient)

This method was deprecated.
Use getSettingsIntent() instead.

Gets an intent to show the Settings screen that allows the user to configure Games-related features for the current game. Note that this must be invoked with startActivityForResult(Intent, int), so that the identity of the calling package can be established.

A RESULT_RECONNECT_REQUIRED may be returned as the resultCode in onActivityResult(int, int, Intent) if the GoogleApiClient ends up in an inconsistent state.

Most applications will not need to call this directly, since the Settings UI is already reachable from most other Games UI screens (achievements, leaderboards, etc.) via a menu item.

Required API: API
Required Scopes: SCOPE_GAMES

Parameters
apiClient The GoogleApiClient to service the call.
Returns
  • An Intent that can be started to view the GoogleApiClient Settings UI.

public static SnapshotsClient getSnapshotsClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of SnapshotsClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static SnapshotsClient getSnapshotsClient (Context context, GoogleSignInAccount account)

Returns a new instance of SnapshotsClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static TurnBasedMultiplayerClient getTurnBasedMultiplayerClient (Context context, GoogleSignInAccount account)

Returns a new instance of TurnBasedMultiplayerClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static TurnBasedMultiplayerClient getTurnBasedMultiplayerClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of TurnBasedMultiplayerClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static VideosClient getVideosClient (Context context, GoogleSignInAccount account)

Returns a new instance of VideosClient for use in a Context.

Parameters
context The Context for this client.
account The GoogleSignInAccount to authorize API calls.

public static VideosClient getVideosClient (Activity activity, GoogleSignInAccount account)

Returns a new instance of VideosClient for use in an Activity.

Parameters
activity The Activity for this client.
account The GoogleSignInAccount to authorize API calls.

public static void setGravityForPopups (GoogleApiClient apiClient, int gravity)

This method was deprecated.
Use setGravityForPopups(int) instead.

Specifies the part of the screen at which games service popups (for example, "welcome back" or "achievement unlocked" popups) will be displayed using gravity.

Default value is TOP|CENTER_HORIZONTAL.

Required API: API
Required Scopes: SCOPE_GAMES

Parameters
apiClient The GoogleApiClient to service the call.
gravity The gravity which controls the placement of games service popups.

public static void setViewForPopups (GoogleApiClient apiClient, View gamesContentView)

This method was deprecated.
Use setViewForPopups(View) instead.

Sets the View to use as a content view for popups.

Required API: API
Required Scopes: SCOPE_GAMES

Parameters
apiClient The GoogleApiClient to service the call.
gamesContentView The view to use as a content view for popups. View cannot be null.

public static PendingResult<Status> signOut (GoogleApiClient apiClient)

This method was deprecated.
Use signOut() instead.

Asynchronously signs the current user out.

This call doesn't disconnect the Google API Client. As no user is signed in after this call is completed, subsequent calls to this client will very likely fail. You should either call disconnect() or finish your Activity after this call.

Required API: API
Required Scopes: SCOPE_GAMES

Parameters
apiClient The GoogleApiClient to service the call.
Returns