public final class

Games

extends Object
java.lang.Object
   ↳ com.google.android.gms.games.Games

Class Overview

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, construct a GoogleApiClient and pass API to addApi(Api). Once you have your GoogleApiClient, call connect() and wait for the onConnected(Bundle) method to be called. The Bundle provided to onConnected may be null. If not null, it can contain the following keys:

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

Summary

Nested Classes
class Games.GamesOptions API configuration parameters for Games. 
Constants
String EXTRA_PLAYER_IDS Used to return a list of player IDs.
Fields
public static final Api<Games.GamesOptions> API Token to pass to addApi(Api) to enable the Games features.
public static final Achievements Achievements Methods for interacting with achivements.
public static final Events Events Methods for interacting with events.
public static final GamesMetadata GamesMetadata Methods for interacting with game metadata.
public static final Invitations Invitations Methods for interacting with invitations.
public static final Leaderboards Leaderboards Methods for interacting with leaderboard data.
public static final Notifications Notifications Methods for interacting with notifications.
public static final Players Players Methods for interacting with players.
public static final Quests Quests Methods for interacting with quests.
public static final RealTimeMultiplayer RealTimeMultiplayer Methods for interacting with real-time multiplayer games.
public static final Requests Requests Methods for interacting with requests.
public static final Scope SCOPE_GAMES Scope for accessing data from Google Play Games.
public static final Snapshots Snapshots Methods for interacting with snapshots.
public static final TurnBasedMultiplayer TurnBasedMultiplayer Methods for interacting with turn-based multiplayer games.
Public Methods
static String getAppId(GoogleApiClient apiClient)
Get the application ID linked to this client instance.
static String getCurrentAccountName(GoogleApiClient apiClient)
Get the name of the currently selected account.
static int getSdkVariant(GoogleApiClient apiClient)
static Intent getSettingsIntent(GoogleApiClient apiClient)
Gets an intent to show the Settings screen that allows the user to configure Games-related features for the current game.
static void setGravityForPopups(GoogleApiClient apiClient, int gravity)
Specifies the part of the screen at which games service popups (for example, "welcome back" or "achievement unlocked" popups) will be displayed using gravity.
static void setViewForPopups(GoogleApiClient apiClient, View gamesContentView)
Sets the View to use as a content view for popups.
static PendingResult<Status> signOut(GoogleApiClient apiClient)
Asynchronously signs the current user out.
[Expand]
Inherited Methods
From class java.lang.Object

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"

Fields

public static final Api<Games.GamesOptions> API

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

Methods for interacting with achivements.

public static final Events Events

Methods for interacting with events.

public static final GamesMetadata GamesMetadata

Methods for interacting with game metadata.

public static final Invitations Invitations

Methods for interacting with invitations.

public static final Leaderboards Leaderboards

Methods for interacting with leaderboard data.

public static final Notifications Notifications

Methods for interacting with notifications.

public static final Players Players

Methods for interacting with players.

public static final Quests Quests

Methods for interacting with quests.

public static final RealTimeMultiplayer RealTimeMultiplayer

Methods for interacting with real-time multiplayer games.

public static final Requests Requests

Methods for interacting with requests.

public static final Scope SCOPE_GAMES

Scope for accessing data from Google Play Games.

public static final Snapshots Snapshots

Methods for interacting with snapshots.

public static final TurnBasedMultiplayer TurnBasedMultiplayer

Methods for interacting with turn-based multiplayer games.

Public Methods

public static String getAppId (GoogleApiClient apiClient)

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)

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 int getSdkVariant (GoogleApiClient apiClient)

public static Intent getSettingsIntent (GoogleApiClient apiClient)

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 void setGravityForPopups (GoogleApiClient apiClient, int gravity)

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)

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)

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