AI-generated Key Takeaways
-
Google Sign-In for Android is outdated and developers should migrate to Credential Manager for enhanced security and user experience, except for Wear OS 3, 4, and 5.0 which requires continued use of Google Sign-In for Android until Credential Manager support is available.
-
After signing in, developers can access basic user profile information, but are strongly advised against using email or user ID for backend server communication; instead, utilize user ID tokens or server auth code flow for security.
-
To get started, developers need to configure their Android Studio project and integrate Google Sign-In into their app before retrieving user profile data.
-
User profile information can be retrieved using
GoogleSignIn.getLastSignedInAccount
but email addresses should not be used for user identification due to potential changes, instead rely on the account's ID for consistent identification.
After you have signed in a user with Google, if you configured Google Sign-In,
with the DEFAULT_SIGN_IN
parameter or the requestProfile
method, you can
access the user's basic profile information. If you configured Google Sign-In
with the requestEmail
method, you can also get their email address.
Before you begin
Retrieve profile information for a signed-in user
Use the GoogleSignIn.getLastSignedInAccount
method to request profile
information for the currently signed in user.
GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(getActivity());
if (acct != null) {
String personName = acct.getDisplayName();
String personGivenName = acct.getGivenName();
String personFamilyName = acct.getFamilyName();
String personEmail = acct.getEmail();
String personId = acct.getId();
Uri personPhoto = acct.getPhotoUrl();
}
For additional profile data that might be available, see
GoogleSignInAccount
.
Note that any of the profile fields can be null
, depending on which scopes
you requested and what information the user's profile includes.