java.lang.Object | |
↳ | com.google.android.gms.auth.api.signin.GoogleSignIn |
Entry point for the Google Sign In API. See GoogleSignInClient
.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets a
GoogleSignInAccount object to use with other authenticated APIs. | |||||||||||
Gets a
GoogleSignInAccount object to use with other authenticated APIs. | |||||||||||
Create a new instance of
GoogleSignInClient | |||||||||||
Create a new instance of
GoogleSignInClient | |||||||||||
Gets the last account that the user signed in with.
| |||||||||||
Returns a
GoogleSignInAccount present in the result data for the associated Activity
started via getSignInIntent() . | |||||||||||
Determines if the given account has been granted permission to all scopes associated with the
given extension.
| |||||||||||
Determines if the given account has been granted permission to all given scopes.
| |||||||||||
Requests a collection of permissions to be granted to the given account.
| |||||||||||
Requests a collection of permissions associated with the given extension to be granted to the
given account.
| |||||||||||
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Gets a GoogleSignInAccount
object to use with other authenticated APIs. Please specify
the additional configurations required by the authenticated API, e.g. FitnessOptions
indicating what data types you'd like to access.
Parameters | |
---|---|
context |
Context |
extension |
GoogleSignInOptionsExtension |
Returns | |
---|---|
GoogleSignInAccount |
Gets a GoogleSignInAccount
object to use with other authenticated APIs. Please specify
the scope(s) required by the authenticated API.
Parameters | |
---|---|
context |
Context |
scope |
Scope |
scopes |
Scope |
Returns | |
---|---|
GoogleSignInAccount |
Create a new instance of GoogleSignInClient
Parameters | |
---|---|
context |
Context : A Context used to provide information about the application's
environment.
See also |
options |
GoogleSignInOptions |
Returns | |
---|---|
GoogleSignInClient |
Create a new instance of GoogleSignInClient
Parameters | |
---|---|
activity |
Activity : An Activity that will be used to manage the lifecycle of the
GoogleSignInClient. |
options |
GoogleSignInOptions : A GoogleSignInOptions used to configure the GoogleSignInClient. It is
recommended to build out a GoogleSignInOptions starting with new
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) }, configuring either ID
token or Server Auth Code options if you have a server. Later, in-context incrementally
auth to additional scopes for other Google services access. |
Returns | |
---|---|
GoogleSignInClient |
A instance of GoogleSignInClient
|
Gets the last account that the user signed in with.
Parameters | |
---|---|
context |
Context |
Returns | |
---|---|
GoogleSignInAccount |
GoogleSignInAccount from last known successful sign-in. If user has never
signed in before or has signed out / revoked access, null is returned.
|
Returns a GoogleSignInAccount
present in the result data for the associated Activity
started via getSignInIntent()
.
A sample usage:
try { // As documented, we return a completed Task in this case and it's safe to directly call // getResult(Class) here (without need to worry about IllegalStateException). GoogleSignIn.getSignedInAccountFromIntent(intent).getResult(ApiException.class); } catch (ApiException apiException) { Log.wtf(TAG, "Unexpected error parsing sign-in result"); }
Parameters | |
---|---|
data |
Intent : the Intent returned via onActivityResult(int, int, Intent) when
sign in completed. |
Returns | |
---|---|
Task<GoogleSignInAccount> |
A completed Task containing a GoogleSignInAccount object. |
See also:
Determines if the given account has been granted permission to all scopes associated with the given extension.
See requestPermissions(Activity, int, GoogleSignInAccount, Scope)
for sample
code.
Parameters | |
---|---|
account |
GoogleSignInAccount : the account to be checked. |
extension |
GoogleSignInOptionsExtension : the extension to be checked. |
Returns | |
---|---|
boolean |
true if the given account has been granted permission to all scopes associated
with the given extension.
|
Determines if the given account has been granted permission to all given scopes.
See requestPermissions(Activity, int, GoogleSignInAccount, GoogleSignInOptionsExtension)
for sample code.
Parameters | |
---|---|
account |
GoogleSignInAccount : the account to be checked. |
scopes |
Scope : the collection of scopes to be checked. |
Returns | |
---|---|
boolean |
true if the given account has been granted permission to all given scopes.
|
Requests a collection of permissions to be granted to the given account. If the account does
not have the requested permissions the user will be presented with a UI for accepting them.
Once the user has accepted or rejected a response will returned via onActivityResult(int, int, Intent)
.
A sample usage:
// Check for your incrementally authed features: if (!GoogleSignIn.hasPermissions( GoogleSignIn.getLastSignedInAccount(this), Drive.SCOPE_APPFOLDER)) { requestPermission(Drive.SCOPE_APPFOLDER, RC_REQUEST_DRIVE_AND_CONTINUE_FILE_CREATION); } else { createDriveFile(); } void createDriveFile() { Drive.getDriveResourceClient(this, GoogleSignIn.getLastSignedInAccount(this)) .createFile(appFolderRoot, changeSet, newContents); ... } private void requestPermission(Scope scope, String requestCode) { GoogleSignIn.requestPermissions( this, requestCode, GoogleSignIn.getLastSignedInAccount(), scope); } // ... @Override void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == Activity.RESULT_OK) { if (RC_REQUEST_DRIVE_AND_CONTINUE_FILE_CREATION == requestCode) { createDriveFile(); } } }
Parameters | |
---|---|
activity |
Activity : the target activity that will receive the response. |
requestCode |
int : code associated with the request. It will match the requestCode
associated with the response returned via onActivityResult(int, int, Intent) . |
account |
GoogleSignInAccount : the account for which the permissions will be requested. If null the
user may have the option to choose. |
scopes |
Scope : the extra collection of scopes to be requested.
|
Requests a collection of permissions associated with the given extension to be granted to the
given account. If the account does not have the requested permissions the user will be
presented with a UI for accepting them. Once the user has accepted or rejected a response will
returned via onActivityResult(int, int, Intent)
.
See also requestPermissions(Activity, int, GoogleSignInAccount, Scope)
A sample usage:
// Check for your incrementally authed features: FitnessOptions fitnessOptions = FitnessOptions.builder() .addDataType(DataType.TYPE_STEP_COUNT_CUMULATIVE, FitnessOptions.ACCESS_READ) .build(); if (!GoogleSignIn.hasPermissions(GoogleSignIn.getLastSignedInAccount(this), fitnessOptions)) { GoogleSignIn.requestPermissions( this, RC_REQUEST_STEP_COUNT_AND_CONTINUE_SUBSCRIPTION, GoogleSignIn.getLastSignedInAccount(this), fitnessOptions); } else { startSubscription(); } void startSubscription() { Fitness.getRecordingClient(this, GoogleSignIn.getLastSignedInAccount()) .subscribe(DataType.TYPE_STEP_COUNT_CUMULATIVE); ... } @Override void onActivityResult(int requestCode, int resultCode, Intent intent) { if (resultCode == Activity.RESULT_OK) { if (RC_REQUEST_STEP_COUNT_AND_CONTINUE_SUBSCRIPTION == requestCode) { startSubscription(); } } }
Parameters | |
---|---|
activity |
Activity : the target activity that will receive the response. |
requestCode |
int : code associated with the request. It will match the requestCode
associated with the response returned via onActivityResult(int, int, Intent) . |
account |
GoogleSignInAccount : the account for which the permissions will be requested. If null the
user may have the option to choose. |
extension |
GoogleSignInOptionsExtension : the extension associated with a set of permissions to be requested.
|
See requestPermissions(Activity, int, GoogleSignInAccount, GoogleSignInOptionsExtension)
.
Parameters | |
---|---|
fragment |
Fragment : the fragment to launch permission resolution Intent from.
|
requestCode |
int |
account |
GoogleSignInAccount |
extension |
GoogleSignInOptionsExtension |
See requestPermissions(Activity, int, GoogleSignInAccount, Scope)
Parameters | |
---|---|
fragment |
Fragment : the fragment to launch permission resolution Intent from.
|
requestCode |
int |
account |
GoogleSignInAccount |
scopes |
Scope |