Sitemap

Member-only story

Google login in android java

2 min readJan 9, 2024

--

  1. Refer to how to integrate firebase to your android project.

https://medium.com/@hasperong/integrate-firebase-with-android-ef138841add0

  1. Add in gradle for deependencies google
implementation("com.google.android.gms:play-services-auth:20.7.0")

2. Method to call gmail login.

private BeginSignInRequest signInRequest;
private SignInClient oneTapClient;

private void googleSignin(){
oneTapClient = Identity.getSignInClient(this);
signInRequest = BeginSignInRequest.builder()
.setGoogleIdTokenRequestOptions(BeginSignInRequest.GoogleIdTokenRequestOptions.builder()
.setSupported(true)
// Your server's client ID, not your Android client ID.
.setServerClientId("yourserverclientId")
// Only show accounts previously used to sign in.
.setFilterByAuthorizedAccounts(false)
.build())
.build();

oneTapClient.beginSignIn(signInRequest)
.addOnSuccessListener(this, new OnSuccessListener<BeginSignInResult>() {
@Override
public void onSuccess(BeginSignInResult result) {
try {
startIntentSenderForResult(
result.getPendingIntent().getIntentSender(), REQ_ONE_TAP,
null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
Log.e(TAG…

--

--

Hasper Ong
Hasper Ong

Written by Hasper Ong

i am mobile developer, i love to share story, and of course i love to write story.