Entry point for the Google Sign In API. See GoogleSignInClient.
| static GoogleSignInAccount |
getAccountForExtension(Context
context,
GoogleSignInOptionsExtension extension)
Gets a
GoogleSignInAccount object to use with other authenticated APIs.
|
| static GoogleSignInAccount |
getAccountForScopes(Context
context, Scope
scope, Scope...
scopes)
Gets a
GoogleSignInAccount object to use with other authenticated APIs.
|
| static GoogleSignInClient | |
| static GoogleSignInClient |
getClient(Activity
activity,
GoogleSignInOptions options)
Create a new instance of
GoogleSignInClient
|
| static GoogleSignInAccount | |
| static Task<GoogleSignInAccount> |
getSignedInAccountFromIntent(Intent data)
Returns a
GoogleSignInAccount present in the result data for the associated
Activity started via
GoogleSignInClient.getSignInIntent().
|
| static boolean |
hasPermissions(GoogleSignInAccount
account,
GoogleSignInOptionsExtension extension)
Determines if the given account has been granted permission to all scopes
associated with the given extension.
|
| static boolean |
hasPermissions(GoogleSignInAccount
account, Scope...
scopes)
Determines if the given account has been granted permission to all given
scopes.
|
| static void |
requestPermissions(Activity
activity, int requestCode,
GoogleSignInAccount account, Scope...
scopes)
Requests a collection of permissions to be granted to the given account.
|
| static void |
requestPermissions(Activity
activity, int requestCode,
GoogleSignInAccount account,
GoogleSignInOptionsExtension extension)
Requests a collection of permissions associated with the given extension to be
granted to the given account.
|
| static void |
requestPermissions(Fragment
fragment, int requestCode,
GoogleSignInAccount account,
GoogleSignInOptionsExtension extension)
|
| static void |
requestPermissions(Fragment
fragment, int requestCode,
GoogleSignInAccount account, Scope...
scopes)
|
Gets a GoogleSignInAccount
object to use with other authenticated APIs. Please specify the additional
configurations required by the authenticated API, e.g. ERROR(/com.google.android.gms.fitness.FitnessOptions) indicating
what data types you'd like to access.
Gets a GoogleSignInAccount
object to use with other authenticated APIs. Please specify the scope(s) required by
the authenticated API.
Create a new instance of GoogleSignInClient
| context |
A Context
used to provide information about the application's environment.
See also |
|---|---|
| options |
Create a new instance of GoogleSignInClient
| activity | An Activity
that will be used to manage the lifecycle of the GoogleSignInClient. |
|---|---|
| options | A ERROR(/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. |
GoogleSignInClientGets the last account that the user signed in with.
ERROR(/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
GoogleSignInClient.getSignInIntent().
A sample usage:
try {
// As documented, we return a completed Task in this case and it's safe to directly call
// getResult(Class<ExceptionType>) 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");
}
| data | the Intent
returned via
Activity.onActivityResult(int, int, Intent) when sign in completed. |
|---|
Task
containing a ERROR(/GoogleSignInAccount)
object.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.
| account | the account to be checked. |
|---|---|
| extension | the extension to be checked. |
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.
| account | the account to be checked. |
|---|---|
| scopes | the collection of scopes to be checked. |
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
Activity.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();
}
}
}
| activity | the target activity that will receive the response. |
|---|---|
| requestCode | code associated with the request. It will match the requestCode
associated with the response returned via
Activity.onActivityResult(int, int, Intent). |
| account | the account for which the permissions will be requested. If null
the user may have the option to choose. |
| scopes | 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
Activity.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();
}
}
}
| activity | the target activity that will receive the response. |
|---|---|
| requestCode | code associated with the request. It will match the requestCode
associated with the response returned via
Activity.onActivityResult(int, int, Intent). |
| account | the account for which the permissions will be requested. If null
the user may have the option to choose. |
| extension | the extension associated with a set of permissions to be requested. |
| fragment | the fragment to launch permission resolution Intent from. |
|---|---|
| requestCode | |
| account | |
| extension |
| fragment | the fragment to launch permission resolution Intent from. |
|---|---|
| requestCode | |
| account | |
| scopes |