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: Ctors | Methods | Inherited Methods | [Expand All]
public static final class

# GoogleApiClient.Builder

extends Object

java.lang.Object
↳ | com.google.android.gms.common.api.GoogleApiClient.Builder

## Class Overview

Builder to configure a `GoogleApiClient`.

Example:

     GoogleApiClient client = new GoogleApiClient.Builder(this)
             .addApi(Plus.API)
             .addScope(Plus.SCOPE_PLUS_LOGIN)
             .setAccountName("users.account.name@gmail.com")
             .build();
     client.connect();

## Summary

Public Constructors
| GoogleApiClient.Builder(Context context) Builder to help construct the `GoogleApiClient` object.
| GoogleApiClient.Builder(Context context, GoogleApiClient.ConnectionCallbacks connectedListener, GoogleApiClient.OnConnectionFailedListener connectionFailedListener) Builder to help construct the `GoogleApiClient` object.

Public Methods
GoogleApiClient.Builder | addApi(Api api) Specify which Apis are requested by your app.
GoogleApiClient.Builder | addApi(Api api, GoogleApiClient.ApiOptions options) Specify which Apis are requested by your app.
GoogleApiClient.Builder | addConnectionCallbacks(GoogleApiClient.ConnectionCallbacks listener) Registers a listener to receive connection events from this `GoogleApiClient`.
GoogleApiClient.Builder | addOnConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener listener) Adds a listener to register to receive connection failed events from this `GoogleApiClient`.
GoogleApiClient.Builder | addScope(Scope scope) Specify the OAuth 2.0 scopes requested by your app.
GoogleApiClient | build() Builds a new `GoogleApiClient` object for communicating with the Google APIs.
GoogleApiClient.Builder | setAccountName(String accountName) Specify an account name on the device that should be used.
GoogleApiClient.Builder | setGravityForPopups(int gravityForPopups) Specifies the part of the screen at which games service popups (for example, "welcome back" or "achievement unlocked" popups) will be displayed using gravity.
GoogleApiClient.Builder | setViewForPopups(View viewForPopups) Sets the `View` to use as a content view for popups.
GoogleApiClient.Builder | useDefaultAccount() Specify that the default account should be used when connecting to services.

[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)

## Public Constructors

#### public GoogleApiClient.Builder (Context context)

Builder to help construct the `GoogleApiClient` object.

##### Parameters

context | The context to use for the connection.

#### public GoogleApiClient.Builder (Context context, GoogleApiClient.ConnectionCallbacks connectedListener, GoogleApiClient.OnConnectionFailedListener connectionFailedListener)

Builder to help construct the `GoogleApiClient` object.

##### Parameters

context | The context to use for the connection.
connectedListener | The listener where the results of the asynchronous `connect()` call are delivered.
connectionFailedListener | The listener which will be notified if the connection attempt fails.

## Public Methods

#### public GoogleApiClient.Builder addApi (Api api)

Specify which Apis are requested by your app. See `Api` for more information.

##### Parameters

api | The Api requested by your app.

##### See Also

- `Api`

#### public GoogleApiClient.Builder addApi (Api api, GoogleApiClient.ApiOptions options)

Specify which Apis are requested by your app. See `Api` for more information.

##### Parameters

api | The Api requested by your app.
options | Any additional parameters required for the specific API.

##### See Also

- `Api`

#### public GoogleApiClient.Builder addConnectionCallbacks (GoogleApiClient.ConnectionCallbacks listener)

Registers a listener to receive connection events from this `GoogleApiClient`. Applications should balance calls to this method with calls to `unregisterConnectionCallbacks(ConnectionCallbacks)` to avoid leaking resources.

If the specified listener is already registered to receive connection events, this method will not add a duplicate entry for the same listener.

Note that the order of messages received here may not be stable, so clients should not rely on the order that multiple listeners receive events in.

##### Parameters

listener | the listener where the results of the asynchronous `connect()` call are delivered.

#### public GoogleApiClient.Builder addOnConnectionFailedListener (GoogleApiClient.OnConnectionFailedListener listener)

Adds a listener to register to receive connection failed events from this `GoogleApiClient`. Applications should balance calls to this method with calls to `unregisterConnectionFailedListener(OnConnectionFailedListener)` to avoid leaking resources.

If the specified listener is already registered to receive connection failed events, this method will not add a duplicate entry for the same listener.

Note that the order of messages received here may not be stable, so clients should not rely on the order that multiple listeners receive events in.

##### Parameters

listener | the listener where the results of the asynchronous `connect()` call are delivered.

#### public GoogleApiClient.Builder addScope (Scope scope)

Specify the OAuth 2.0 scopes requested by your app. See `Scopes` for more information.

##### Parameters

scope | The OAuth 2.0 scopes requested by your app.

##### See Also

- `Scopes`

#### public GoogleApiClient build ()

Builds a new `GoogleApiClient` object for communicating with the Google APIs.

##### Returns

- The `GoogleApiClient` object.

#### public GoogleApiClient.Builder setAccountName (String accountName)

Specify an account name on the device that should be used. If this is never called, the client will use the current default account for Google Play services for this application.

##### Parameters

accountName | The account name on the device that should be used by `GoogleApiClient`.

#### public GoogleApiClient.Builder setGravityForPopups (int gravityForPopups)

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

##### Parameters

gravityForPopups | The gravity which controls the placement of games service popups.

#### public GoogleApiClient.Builder setViewForPopups (View viewForPopups)

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

##### Parameters

viewForPopups | The view to use as a content view for popups. View cannot be null.

#### public GoogleApiClient.Builder useDefaultAccount ()

Specify that the default account should be used when connecting to services.