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

# GoogleApiClient

extends Object

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

## Class Overview

The main entry point for Google Play services integration.

GooglePlayServicesClient is used with a variety of static methods. Some of these methods require that GoogleApiClient be connected, some will queue up calls before GoogleApiClient is connected; check the specific API documentation to determine whether you need to be connected.

Before any operation is executed, the GoogleApiClient must be connected using the `connect()` method. The client is not considered connected until the `onConnected(Bundle)` callback has been called.

When your app is done using this client, call `disconnect()`, even if the async result from `connect()` has not yet been delivered.

You should instantiate this object in your Activity's `onCreate(Bundle)` method and then call `connect()` in `onStart()` and `disconnect()` in `onStop()`, regardless of the state.

## Summary

Nested Classes
interface | GoogleApiClient.ApiOptions | Base interface for API options.
class | GoogleApiClient.Builder | Builder to configure a `GoogleApiClient`.
interface | GoogleApiClient.ConnectionCallbacks | Provides callbacks that are called when the client is connected or disconnected from the service.
interface | GoogleApiClient.OnConnectionFailedListener | Provides callbacks for scenarios that result in a failed attempt to connect the client to the service.

Public Methods
void | connect() Connects the client to Google Play services.
void | disconnect() Closes the connection to Google Play services.
boolean | isConnected() Checks if the client is currently connected to the service, so that requests to other methods will succeed.
boolean | isConnecting() Checks if the client is attempting to connect to the service.
boolean | isConnectionCallbacksRegistered(GoogleApiClient.ConnectionCallbacks listener) Returns true if the specified listener is currently registered to receive connection events.
boolean | isConnectionFailedListenerRegistered(GoogleApiClient.OnConnectionFailedListener listener) Returns true if the specified listener is currently registered to receive connection failed events.
void | reconnect() Closes the current connection to Google Play services and creates a new connection.
void | registerConnectionCallbacks(GoogleApiClient.ConnectionCallbacks listener) Registers a listener to receive connection events from this `GoogleApiClient`.
void | registerConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener listener) Registers a listener to receive connection failed events from this `GoogleApiClient`.
void | unregisterConnectionCallbacks(GoogleApiClient.ConnectionCallbacks listener) Removes a connection listener from this `GoogleApiClient`.
void | unregisterConnectionFailedListener(GoogleApiClient.OnConnectionFailedListener listener) Removes a connection failed listener from the `GoogleApiClient`.

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

#### public void connect ()

Connects the client to Google Play services. This method returns immediately, and connects to the service in the background. If the connection is successful, `onConnected(Bundle)` is called and enqueued items are executed. On a failure, `onConnectionFailed(ConnectionResult)` is called.

#### public void disconnect ()

Closes the connection to Google Play services. No calls can be made using this client after calling this method. Any queued tasks will be cleared and the tasks and callbacks will never be executed.

##### See Also

- `connect()`

#### public boolean isConnected ()

Checks if the client is currently connected to the service, so that requests to other methods will succeed. Applications should guard client actions caused by the user with a call to this method.

##### Returns

- true if the client is connected to the service.

#### public boolean isConnecting ()

Checks if the client is attempting to connect to the service.

##### Returns

- true if the client is attempting to connect to the service.

#### public boolean isConnectionCallbacksRegistered (GoogleApiClient.ConnectionCallbacks listener)

Returns true if the specified listener is currently registered to receive connection events.

##### Parameters

listener | The listener to check for.

##### Returns

- true if the specified listener is currently registered to receive connection events.

##### See Also

- `registerConnectionCallbacks(ConnectionCallbacks)`
- `unregisterConnectionCallbacks(ConnectionCallbacks)`

#### public boolean isConnectionFailedListenerRegistered (GoogleApiClient.OnConnectionFailedListener listener)

Returns true if the specified listener is currently registered to receive connection failed events.

##### Parameters

listener | The listener to check for.

##### Returns

- true if the specified listener is currently registered to receive connection failed events.

##### See Also

- `registerConnectionFailedListener(OnConnectionFailedListener)`
- `unregisterConnectionFailedListener(OnConnectionFailedListener)`

#### public void reconnect ()

Closes the current connection to Google Play services and creates a new connection.

This method closes the current connection then returns immediately and reconnects to the service in the background.

After calling this method, your application will receive `onConnected(Bundle)` if the connection is successful, or `onConnectionFailed(ConnectionResult)` if the connection failed.

##### See Also

- `connect()`
- `disconnect()`

#### public void registerConnectionCallbacks (GoogleApiClient.ConnectionCallbacks listener)

Registers a listener to receive connection events from this `GoogleApiClient`. If the service is already connected, the listener's `onConnected(Bundle)` method will be called immediately. 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, but will still call the listener's `onConnected(Bundle)` method if currently connected.

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 void registerConnectionFailedListener (GoogleApiClient.OnConnectionFailedListener listener)

Registers a listener to receive connection failed events from this `GoogleApiClient`. Unlike `registerConnectionCallbacks(GoogleApiClient.ConnectionCallbacks)`, if the service is not already connected, the listener's `onConnectionFailed(ConnectionResult)` method will not be called immediately. 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 void unregisterConnectionCallbacks (GoogleApiClient.ConnectionCallbacks listener)

Removes a connection listener from this `GoogleApiClient`. Note that removing a listener does not generate any callbacks.

If the specified listener is not currently registered to receive connection events, this method will have no effect.

##### Parameters

listener | the listener to unregister.

#### public void unregisterConnectionFailedListener (GoogleApiClient.OnConnectionFailedListener listener)

Removes a connection failed listener from the `GoogleApiClient`. Note that removing a listener does not generate any callbacks.

If the specified listener is not currently registered to receive connection failed events, this method will have no effect.

##### Parameters

listener | the listener to unregister.