public class

PlusClient

extends Object
implements GooglePlayServicesClient
java.lang.Object
   ↳ com.google.android.gms.plus.PlusClient

Class Overview

The main entry point for Google+ integration. Use the PlusClient after the asynchronous connect() method has been called and your listener's onConnected() method is called.

When your app is done using PlusClient, 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

Constants
String DEFAULT_ACCOUNT Specify < > as the account name to indicate that the default account on the device should be used.
Public Constructors
PlusClient(Context context, String accountName, GooglePlayServicesClient.ConnectionCallbacks connectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener connectionFailedListener, String... scopes)
Creates a Google+ client to connect to Google Play services.
PlusClient(Context context, GooglePlayServicesClient.ConnectionCallbacks connectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener connectionFailedListener, String... scopes)
Creates a Google+ client to connect to Google Play services.
PlusClient(Context context, GooglePlayServicesClient.ConnectionCallbacks connectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener connectionFailedListener)
Creates a Google+ client to connect to Google Play services with a DEFAULT_ACCOUNT and without OAuth 2.0 scopes.
Public Methods
void clearDefaultAccount()
Clears the default account for this PlusClient instance.
void connect()
Connects the client to Google Play services.
void disconnect()
Closes the connection to Google Play services.
String getAccountName()
Gets the account name resolved by Google Play services.
boolean isConnected()
Checks if the client is currently connected to the service, so that requests to other methods will succeed.
boolean isConnectionCallbacksRegistered( GooglePlayServicesClient.ConnectionCallbacks listener)
Returns true if the specified listener is currently registered to receive connection events.
boolean isConnectionFailedListenerRegistered( GooglePlayServicesClient.OnConnectionFailedListener listener)
Returns true if the specified listener is currently registered to receive connection failed events.
void registerConnectionCallbacks( GooglePlayServicesClient.ConnectionCallbacks listener)
Registers a listener to receive connection events from this GooglePlayServicesClient.
void registerConnectionFailedListener( GooglePlayServicesClient.OnConnectionFailedListener listener)
Registers a listener to receive connection failed events from this GooglePlayServicesClient.
void unregisterConnectionCallbacks( GooglePlayServicesClient.ConnectionCallbacks listener)
Removes a connection listener from this GooglePlayServicesClient.
void unregisterConnectionFailedListener( GooglePlayServicesClient.OnConnectionFailedListener listener)
Removes a connection failed listener from the GooglePlayServicesClient.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.android.gms.common.GooglePlayServicesClient

Constants

public static final String DEFAULT_ACCOUNT

Specify < > as the account name to indicate that the default account on the device should be used.

Constant Value: "< >"

Public Constructors

public PlusClient (Context context, String accountName, GooglePlayServicesClient.ConnectionCallbacks connectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener connectionFailedListener, String... scopes)

Creates a Google+ client to connect to Google Play services.

Parameters
context The context to use for the connection.
accountName The name of the account to use.
connectionCallbacks The callbacks invoked when the client is connected.
connectionFailedListener The listener which will be notified if the connection attempt fails.
scopes The OAuth 2.0 scopes that your application is requesting access to (see Scopes for details).

public PlusClient (Context context, GooglePlayServicesClient.ConnectionCallbacks connectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener connectionFailedListener, String... scopes)

Creates a Google+ client to connect to Google Play services.

Parameters
context The context to use for the connection.
connectionCallbacks The callbacks invoked when the client is connected.
connectionFailedListener The listener which will be notified if the connection attempt fails.
scopes The OAuth 2.0 scopes that your application is requesting access to (see Scopes for details).

public PlusClient (Context context, GooglePlayServicesClient.ConnectionCallbacks connectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener connectionFailedListener)

Creates a Google+ client to connect to Google Play services with a DEFAULT_ACCOUNT and without OAuth 2.0 scopes.

Parameters
context The context to use for the connection.
connectionCallbacks The callbacks invoked when the client is connected.
connectionFailedListener The listener which will be notified if the connection attempt fails.

Public Methods

public void clearDefaultAccount ()

Clears the default account for this PlusClient instance. Use this method to allow the user to choose a different account the next time connect() is called.

This operation doesn't affect existing connected instances of PlusClient. This client and any others will continue to use the same account. You should call disconnect() and connect() if you want to reset the account.

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() is called. On a failure, onConnectionFailed(ConnectionResult) is called.

public void disconnect ()

Closes the connection to Google Play services. No calls can be made on this object after calling this method.

public String getAccountName ()

Gets the account name resolved by Google Play services. The permission <uses-permission android:name="android.permission.GET_ACCOUNTS" /> must be declared in your AndroidManifest.xml to use this method.

Returns
  • The account name. If the user has not selected an account, null is returned.
Throws
SecurityException If your app doesn't have the GET_ACCOUNTS permission.

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 isConnectionCallbacksRegistered (GooglePlayServicesClient.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.

public boolean isConnectionFailedListenerRegistered (GooglePlayServicesClient.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.

public void registerConnectionCallbacks (GooglePlayServicesClient.ConnectionCallbacks listener)

Registers a listener to receive connection events from this GooglePlayServicesClient. If we are already connected, the listener's onConnected() 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() 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 (GooglePlayServicesClient.OnConnectionFailedListener listener)

Registers a listener to receive connection failed events from this GooglePlayServicesClient. Unlike registerConnectionCallbacks(GooglePlayServicesClient.ConnectionCallbacks), if we are 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 (GooglePlayServicesClient.ConnectionCallbacks listener)

Removes a connection listener from this GooglePlayServicesClient. 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 (GooglePlayServicesClient.OnConnectionFailedListener listener)

Removes a connection failed listener from the GooglePlayServicesClient. 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.
No examples for this method.
Frequently called with: [Clear]
Portions of this page are reproduced from work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License. The original page is available here.