Adjacent Files

Project Info

. > BaseGameUtils > src > main > java > com > google > example > games > basegameutils > GameHelper.java

GameHelperListener

Type: public interface

Listener for sign-in success or failure events.

onSignInFailed

Type: void

Called when sign-in fails. As a result, a “Sign-In” button can be shown to the user; when that button is clicked, call

to this method mean an error; it may be a result of the fact that automatic sign-in could not proceed because user interaction was required (consent dialogs). So implementations of this method should NOT display an error message unless a call to @link{GamesHelper# hasSignInError} indicates that an error indeed occurred.

onSignInSucceeded

Type: void

Called when sign-in succeeds.

mActivity

Type: Activity

The Activity we are bound to. We need to keep a reference to the Activity because some games methods require an Activity (a Context won’t do). We are careful not to leak these references: we release them on onStop().

GameHelper

Type: public

Construct a GameHelper object, initially tied to the given Activity. After constructing this object, call @link{setup} from the onCreate() method of your Activity.

Parameter Name Description
clientsToUse the API clients to use (a combination of the CLIENT_flags, or CLIENT_ALL to mean all clients).

setMaxAutoSignInAttempts

Type: public void

Sets the maximum number of automatic sign-in attempts to be made on application startup. This maximum is over the lifetime of the application (it is stored in a SharedPreferences file). So, for example, if you specify 2, then it means that the user will be prompted to sign in on app startup the first time and, if they cancel, a second time the next time the app starts, and, if they cancel that one, never again. Set to 0 if you do not want the user to be prompted to sign in on application startup.

setGamesApiOptions

Type: public void

Sets the options to pass when setting up the Games API. Call before setup().

setPlusApiOptions

Type: public void

Sets the options to pass when setting up the Plus API. Call before setup().

createApiClientBuilder

Type: public GoogleApiClient.Builder

Creates a GoogleApiClient.Builder for use with @link{#setup}. Normally, you do not have to do this; use this method only if you need to make nonstandard setup (e.g. adding extra scopes for other APIs) on the GoogleApiClient.Builder before calling @link{#setup}.

setup

Type: public void

Performs setup on this GameHelper object. Call this from the onCreate() method of your Activity. This will create the clients and do a few other initialization tasks. Next, call @link{#onStart} from the onStart() method of your Activity.

Parameter Name Description
listener The listener to be notified of sign-in events.

getApiClient

Type: public GoogleApiClient

Returns the GoogleApiClient object. In order to call this method, you must have called @link{setup}.

isSignedIn

Type: public boolean

Returns whether or not the user is signed in.

isConnecting

Type: public boolean

Returns whether or not we are currently connecting

hasSignInError

Type: public boolean

Returns whether or not there was a (non-recoverable) error during the sign-in process.

getSignInError

Type: public SignInFailureReason

Returns the error that happened during the sign-in process, null if no error occurred.

onStart

Type: public void

Call this method from your Activity’s onStart().

onStop

Type: public void

Call this method from your Activity’s onStop().

getInvitationId

Type: public String

Returns the invitation ID received through an invitation notification. This should be called from your GameHelperListener’s

invitation available. In that case, accept the invitation.

Returned Value: The id of the invitation, or null if none was received.

getInvitation

Type: public Invitation

Returns the invitation received through an invitation notification. This should be called from your GameHelperListener’s

invitation available. In that case, accept the invitation.

Returned Value: The invitation, or null if none was received.

getTurnBasedMatch

Type: public TurnBasedMatch

Returns the tbmp match received through an invitation notification. This should be called from your GameHelperListener’s

match available.

Returned Value: The match, or null if none was received.

getRequests

Type: public ArrayList<GameRequest>

Returns the requests received through the onConnected bundle. This should be called from your GameHelperListener’s

incoming requests that must be handled.

Returned Value: The requests, or null if none were received.

enableDebugLog

Type: public void

Enables debug logging

signOut

Type: public void

Sign out and disconnect from the APIs.

onActivityResult

Type: public void

Handle activity result. Call this method from your Activity’s onActivityResult callback. If the activity result pertains to the sign-in process, processes it appropriately.

beginUserInitiatedSignIn

Type: public void

Starts a user-initiated sign-in flow. This should be called when the user clicks on a “Sign In” button. As a result, authentication/consent dialogs may show up. At the end of the process, the GameHelperListener’s onSignInSucceeded() or onSignInFailed() methods will be called.

reconnectClient

Type: public void

Disconnects the API client, then connects again.

onConnected

Type: @Override public void

Called when we successfully obtain a connection to a client.

onConnectionFailed

Type: @Override public void

Handles a connection failure.

resolveConnectionResult

Type: void

Attempts to resolve a connection failure. This will usually involve starting a UI flow that lets the user give the appropriate consents necessary for sign-in to work.

giveUp

Type: void

Give up on signing in due to an error. Shows the appropriate error message to the user, using a standard error dialog as appropriate to the cause of the error. That dialog will indicate to the user how the problem can be solved (for example, re-enable Google Play Services, upgrade to a new version, etc).

onConnectionSuspended

Type: @Override public void

Called when we are disconnected from the Google API client.

showFailureDialog

Type: public static void

Shows an error dialog that’s appropriate for the failure reason.

This site may do shady things with cookies and stuff because it's evil. Please don't read my privacy policy. close