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, visit the getting started guide.

Nested Class Summary

class Games.GamesOptions API configuration parameters for Games. 

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 is deprecated. This is no longer necessary to provide.
public static final Achievements Achievements This field is deprecated. Use getAchievementsClient(Activity, GoogleSignInAccount) or getAchievementsClient(Context, GoogleSignInAccount) instead.
public static final Events Events This field is deprecated. Use getEventsClient(Activity, GoogleSignInAccount) or getEventsClient(Context, GoogleSignInAccount) instead.
public static final GamesMetadata GamesMetadata This field is deprecated. Use getGamesMetadataClient(Activity, GoogleSignInAccount) or getGamesMetadataClient(Context, GoogleSignInAccount) instead.
public static final Leaderboards Leaderboards This field is deprecated. Use getLeaderboardsClient(Activity, GoogleSignInAccount) or getLeaderboardsClient(Context, GoogleSignInAccount) instead.
public static final Players Players This field is deprecated. Use getPlayersClient(Activity, GoogleSignInAccount) or getPlayersClient(Context, GoogleSignInAccount) instead.
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 Scope SCOPE_GAMES_SNAPSHOTS Scope for accessing SnapshotsClient API.
public static final Snapshots Snapshots This field is deprecated. Use getSnapshotsClient(Activity, GoogleSignInAccount) or getSnapshotsClient(Context, GoogleSignInAccount) instead.
public static final Stats Stats This field is deprecated. Use getPlayerStatsClient(Activity, GoogleSignInAccount) or getPlayerStatsClient(Context, GoogleSignInAccount) instead.
public static final Videos Videos This field is 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 AchievementsClient
getAchievementsClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of AchievementsClient for use in a Context.
static AchievementsClient
getAchievementsClient(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of AchievementsClient for use in an Activity.
static String
getCurrentAccountName(GoogleApiClient apiClient)
This method is deprecated. Use getCurrentAccountName() instead.
static EventsClient
getEventsClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of EventsClient for use in a Context.
static EventsClient
getEventsClient(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of EventsClient for use in an Activity.
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(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
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 GamesClient
getGamesClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of GamesClient for use in a Context.
static GamesMetadataClient
getGamesMetadataClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of GamesMetadataClient for use in a Context.
static GamesMetadataClient
getGamesMetadataClient(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of GamesMetadataClient for use in an Activity.
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 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 LeaderboardsClient
getLeaderboardsClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of LeaderboardsClient for use in a Context.
static LeaderboardsClient
getLeaderboardsClient(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of LeaderboardsClient for use in an Activity.
static PlayerStatsClient
getPlayerStatsClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of PlayerStatsClient for use in a Context.
static PlayerStatsClient
getPlayerStatsClient(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of PlayerStatsClient 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(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of PlayersClient for use in an Activity.
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 PlayersClient
getPlayersClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of PlayersClient for use in a Context.
static SnapshotsClient
getSnapshotsClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of SnapshotsClient for use in a Context.
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 SnapshotsClient
getSnapshotsClient(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of SnapshotsClient for use in an Activity.
static VideosClient
getVideosClient(Context context, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of VideosClient for use in a Context.
static VideosClient
getVideosClient(Activity activity, GoogleSignInAccount account, Games.GamesOptions options)
Returns a new instance of VideosClient 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 PendingResult<Status>
signOut(GoogleApiClient apiClient)
This method is 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).

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 is 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 is deprecated.
Use getAchievementsClient(Activity, GoogleSignInAccount) or getAchievementsClient(Context, GoogleSignInAccount) instead.

Methods for interacting with achievements.

public static final Events Events

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

Methods for interacting with events.

public static final GamesMetadata GamesMetadata

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

Methods for interacting with game metadata.

public static final Leaderboards Leaderboards

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

Methods for interacting with leaderboard data.

public static final Players Players

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

Methods for interacting with players.

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 Scope SCOPE_GAMES_SNAPSHOTS

Scope for accessing SnapshotsClient API.

public static final Snapshots Snapshots

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

Methods for interacting with snapshots.

public static final Stats Stats

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

Methods for interacting with game and player stats.

public static final Videos Videos

This field is 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 AchievementsClient getAchievementsClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static AchievementsClient getAchievementsClient (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static String getCurrentAccountName (GoogleApiClient apiClient)

This method is 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 (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static EventsClient getEventsClient (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

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 (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

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 GamesClient getGamesClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static GamesMetadataClient getGamesMetadataClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static GamesMetadataClient getGamesMetadataClient (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

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 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 LeaderboardsClient getLeaderboardsClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static LeaderboardsClient getLeaderboardsClient (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static PlayerStatsClient getPlayerStatsClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static PlayerStatsClient getPlayerStatsClient (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

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 (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

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 PlayersClient getPlayersClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static SnapshotsClient getSnapshotsClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

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 SnapshotsClient getSnapshotsClient (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static VideosClient getVideosClient (Context context, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

public static VideosClient getVideosClient (Activity activity, GoogleSignInAccount account, Games.GamesOptions options)

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.
options The Games.GamesOptions for this client.

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 PendingResult<Status> signOut (GoogleApiClient apiClient)

This method is 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