Code for Google provider

Now that we have all the necessary settings in place, the following piece of code helps in initializing Google Sign-in for your project:

private List<AuthUI.IdpConfig> getAuthProviderList() {
List<AuthUI.IdpConfig> providers = new ArrayList<>();
providers.add(new
AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());
providers.add(new
AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build());
return providers;
}

private void authenticate() {
startActivityForResult(
AuthUI.getInstance().createSignInIntentBuilder()
.setAvailableProviders(getAuthProviderList())
.setIsSmartLockEnabled(false)
.build(),
REQUEST_CODE);
}

This code is self-explanatory, as we have just one line of code to enable Google Sign-in. We also have a lot of control over how the application looks by adding a logo and custom theme inside an AuthUI builder:

When the user clicks on the Sign in with Google method, it will allow the user to log in through their existing accounts on the device or it will ask the user to log in from Google:

This screenshot shows the email addresses that the user can use to authorize. If there is another account he wishes to choose, he can do that by clicking Use another account. On successful signup, you can see user account creation inside the Firebase console. 

User added from Google Sign-in will be seen as follows:

Using the FirebaseUser object, a developer can access the profile photograph, name, email address, and a lot more profile details.