GoogleApiClient.Builder

public static final classGoogleApiClient.BuilderextendsObject

This class is deprecated.
UseGoogleApi based APIs instead. SeeMoving Past GoogleApiClient.

Builder to configure aGoogleApiClient.

Example:

GoogleApiClient client = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */,
this /* OnConnectionFailedListener */)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
.setAccountName( "users.account.name@gmail" )
.build();

Public Constructor Summary

Builder(Context context)
Builder to help construct theGoogleApiClient object.
Builder(Context context, GoogleApiClient.ConnectionCallbacksconnectedListener, GoogleApiClient.OnConnectionFailedListenerconnectionFailedListener)
Builder to help construct theGoogleApiClient object.

Public Method Summary

<O extendsApi.ApiOptions.HasOptions> GoogleApiClient.Builder
addApi(Api<O> api, O options)
Specify which Apis are requested by your app.
GoogleApiClient.Builder
addApi(Api<? extendsApi.ApiOptions.NotRequiredOptions> api)
Specify which Apis are requested by your app.
<O extendsApi.ApiOptions.HasOptions> GoogleApiClient.Builder
addApiIfAvailable(Api<O> api, O options,Scope... scopes)
Specify which Apis should attempt to connect, but are not strictly required for your app.
<T extendsApi.ApiOptions.NotRequiredOptions> GoogleApiClient.Builder
addApiIfAvailable(Api<? extendsApi.ApiOptions.NotRequiredOptions> api,Scope... scopes)
Specify which Apis should attempt to connect, but are not strictly required for 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 newGoogleApiClient object for communicating with the Google APIs.
GoogleApiClient.Builder
enableAutoManage(FragmentActivity fragmentActivity, GoogleApiClient.OnConnectionFailedListener unresolvedConnectionFailedListener)
Enables automatic lifecycle management in a support library FragmentActivitythat connects the client in FragmentActivity.onStart()and disconnects it in FragmentActivity.onStop().
GoogleApiClient.Builder
enableAutoManage(FragmentActivity fragmentActivity, int clientId, GoogleApiClient.OnConnectionFailedListener unresolvedConnectionFailedListener)
Enables automatic lifecycle management in a support library FragmentActivitythat connects the client in FragmentActivity.onStart()and disconnects it in FragmentActivity.onStop().
GoogleApiClient.Builder
setAccountName(StringaccountName)
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
setHandler(Handlerhandler)
Sets aHandler to indicate which thread to use when invoking callbacks.
GoogleApiClient.Builder
setViewForPopups(View viewForPopups)
Sets theViewto use as a content view for popups.
GoogleApiClient.Builder
useDefaultAccount()
Specify that the default account should be used when connecting to services.

Inherited Method Summary

Public Constructors

publicBuilder(Context context)

Builder to help construct theGoogleApiClient object.

Parameters
context The context to use for the connection.

publicBuilder(Contextcontext, GoogleApiClient.ConnectionCallbacksconnectedListener, GoogleApiClient.OnConnectionFailedListenerconnectionFailedListener)

Builder to help construct theGoogleApiClient object.

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

Public Methods

publicGoogleApiClient.Builder addApi(Api<O> api, O options)

Specify which Apis are requested by your app. SeeApifor more information.

Parameters
api The Api requested by your app.
options Any additional parameters required for the specific AP
See Also

publicGoogleApiClient.Builder addApi(Api<? extendsApi.ApiOptions.NotRequiredOptions> api)

Specify which Apis are requested by your app. SeeApifor more information.

Parameters
api The Api requested by your app.
See Also

publicGoogleApiClient.Builder addApiIfAvailable(Api<O> api, O options,Scope... scopes)

Specify which Apis should attempt to connect, but are not strictly required for your app. The GoogleApiClient will try to connect to these Apis, but will not necessarily fail if there are only errors when connecting to an unavailable Api added with this method. SeeApifor more information.

Parameters
api The Api requested by your app.
options
scopes Scopes required by this API.
See Also

publicGoogleApiClient.Builder addApiIfAvailable(Api<? extendsApi.ApiOptions.NotRequiredOptions> api,Scope... scopes)

Specify which Apis should attempt to connect, but are not strictly required for your app. The GoogleApiClient will try to connect to these Apis, but will not necessarily fail if there are only errors when connecting to an unavailable Api added with this method. SeeApifor more information.

Parameters
api The Api requested by your app.
scopes Scopes required by this API.
See Also

publicGoogleApiClient.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 GoogleApiClient.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 GoogleApiClient.connect()call are delivered.

publicGoogleApiClient.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 GoogleApiClient.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 GoogleApiClient.connect()call are delivered.

publicGoogleApiClient.Builder addScope(Scope scope)

Specify the OAuth 2.0 scopes requested by your app. SeeScopesfor more information.

It is an error to call this method when usingAuth.GOOGLE_SIGN_IN_API. Use GoogleSignInOptions.Builder.requestScopes(Scope, Scope...)instead.

Parameters
scope The OAuth 2.0 scopes requested by your app.
See Also

publicGoogleApiClient build()

Builds a newGoogleApiClient object for communicating with the Google APIs.

Returns

publicGoogleApiClient.Builder enableAutoManage(FragmentActivity fragmentActivity, GoogleApiClient.OnConnectionFailedListener unresolvedConnectionFailedListener)

Enables automatic lifecycle management in a support libraryFragmentActivity that connects the client in FragmentActivity.onStart()and disconnects it in FragmentActivity.onStop().

It handles user recoverable errors appropriately and calls OnConnectionFailedListener#onConnectionFailedon the unresolvedConnectionFailedListener if theConnectionResult has no resolution. This eliminates most of the boiler plate associated with using GoogleApiClient.

This method can only be used if this GoogleApiClient will be the only auto-managed client in the containing activity. The api client will be assigned a default client id.

When using this option, build()must be called from the main thread.

Parameters
fragmentActivity The activity that uses theGoogleApiClient. For lifecycle management to work correctly the activity must call its parent's Activity.onActivityResult(int, int, android.content.Intent).
unresolvedConnectionFailedListener Called if the connection failed and there was no resolution or the user chose not to complete the provided resolution. If this listener is called, the client will no longer be auto-managed, and a new instance must be built. In the event that the user chooses not to complete a resolution, theConnectionResult will have a status code ofConnectionResult.CANCELED.
Throws
NullPointerException if fragmentActivity is null
IllegalStateException if another GoogleApiClient is already being auto-managed with the default clientId.

publicGoogleApiClient.Builder enableAutoManage(FragmentActivity fragmentActivity, int clientId, GoogleApiClient.OnConnectionFailedListener unresolvedConnectionFailedListener)

Enables automatic lifecycle management in a support libraryFragmentActivity that connects the client in FragmentActivity.onStart()and disconnects it in FragmentActivity.onStop().

It handles user recoverable errors appropriately and calls if theConnectionResult has no resolution. This eliminates most of the boiler plate associated with using GoogleApiClient.

When using this option, build()must be called from the main thread.

Parameters
fragmentActivity The activity that uses theGoogleApiClient. For lifecycle management to work correctly the activity must call its parent's Activity.onActivityResult(int, int, android.content.Intent).
clientId A non-negative identifier for this client. At any given time, only one auto-managed client is allowed per id. To reuse an id you must first call GoogleApiClient.stopAutoManage(FragmentActivity)on the previous client.
Throws
NullPointerException if fragmentActivity is null
IllegalArgumentException if clientId is negative.
IllegalStateException if clientId is already being auto-managed.

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

It is an error to call this method when usingAuth.GOOGLE_SIGN_IN_API. Use #setAccountName(String)instead.

Parameters
accountName The account name on the device that should be used byGoogleApiClient.

publicGoogleApiClient.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 isGravity.TOP|Gravity.CENTER_HORIZONTAL.

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

publicGoogleApiClient.Builder setHandler(Handler handler)

Sets aHandlerto indicate which thread to use when invoking callbacks. Will not be used directly to handle callbacks. If this is not called then the application's main thread will be used.

publicGoogleApiClient.Builder setViewForPopups(View viewForPopups)

Sets theViewto use as a content view for popups.

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

publicGoogleApiClient.Builder useDefaultAccount()

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