Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

close

- - Get Started
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
    - Get the SDK
  - Google Services
- - Google Play
  - Publishing
  - Promoting
  - App Quality
  - Spotlight
  - Open Distribution

## Results

Loading...
Summary: Nested Classes | 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)`.

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.

Fields
public static final Api | 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 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 RealTimeMultiplayer | RealTimeMultiplayer | Methods for interacting with real-time multiplayer games.
public static final Scope | SCOPE_GAMES | Scope for accessing data from Google Play Games.
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

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

## Fields

#### public static final Api 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 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 RealTimeMultiplayer RealTimeMultiplayer

Methods for interacting with real-time multiplayer games.

#### public static final Scope SCOPE_GAMES

Scope for accessing data from Google Play Games.

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

- `PendingResult` to access the data when available.