Summary: Nested Classes | Constants | Fields | Methods | Inherited Methods | [Expand All]
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:

- `EXTRA_INVITATION` if the user wanted to accept an invitation to a multiplayer game. The value contained here is an `Invitation` which can be accessed with `getParcelable(String)`.
- `EXTRA_TURN_BASED_MATCH` if the user wanted to take action in a turn-based match. The value contained here is a `TurnBasedMatch` which can be accessed with `getParcelable(String)`.
- `EXTRA_REQUESTS` if the user wanted to accept one or more requests. The value contained here is a list of `GameRequest` objects which can be accessed with `getParcelableArrayList(String)`.
- `EXTRA_SNAPSHOT_METADATA` if the user wanted to resume a saved game. The value contained here is a `SnapshotMetadata` object which can be accessed with `getParcelable(String)`.
- `EXTRA_QUEST` if the user wanted to accept a specific quest. The value contained here is a `Quest` which can be accessed with `getParcelable(String)`.

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.
String | EXTRA_STATUS | Used to return a `Status` object from activities.

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 achievements.
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 Stats | Stats | Methods for interacting with game and player stats.
public static final TurnBasedMultiplayer | TurnBasedMultiplayer | Methods for interacting with turn-based multiplayer games.
public static final Videos | Videos | Methods for interacting with video recording.

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
Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## 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 Also

- `getSelectOpponentsIntent(GoogleApiClient, int, int)`
- `getSelectOpponentsIntent(GoogleApiClient, 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

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

#### 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 Stats Stats

Methods for interacting with game and player stats.

#### public static final TurnBasedMultiplayer TurnBasedMultiplayer

Methods for interacting with turn-based multiplayer games.

#### public static final Videos Videos

Methods for interacting with video recording.

## 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 `&lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;` 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

- `PendingResult` to access the data when available.