I’m working with Android’s Credential Manager to implement Google account authentication in my app. The integration works fine overall, but I’m running into a strange behavior with different Google accounts.
When I test with one Gmail account, the credential.getId() method gives me back the proper email address like [email protected]. But when I switch to my second Gmail account for testing, the same method returns a long numeric identifier like 123456789012345678901 instead of the email.
Based on what I read in Google’s documentation, the getId() function should always provide the email address for the logged-in Google account.
private val googleSignInOption = GetSignInWithGoogleOption.Builder(
serverClientId = CLIENT_ID_SERVER
).build()
private suspend fun handleGoogleAuth(
context: Activity,
callback: (GoogleIdTokenCredential) -> Unit
) {
val credentialRequest = GetCredentialRequest.Builder()
.addCredentialOption(googleSignInOption)
.build()
val authResult = credentialManager.getCredential(context, credentialRequest)
val userCredential = authResult.credential
Log.d("Auth", "User ID: ${userCredential.id}")
}
Had this exact problem a few months ago - drove me nuts for days! It’s not your code, it’s Google account settings. Some accounts restrict email visibility for third-party apps, so Credential Manager falls back to the numeric Google ID instead of showing the email. Usually happens with newer accounts or when users tweak their privacy settings. Check the account dashboard under “Data & privacy” and look at third-party app permissions to confirm. The numeric ID still works as a unique identifier though. You could pull the email from the ID token payload instead, or just handle both cases in your auth flow.
This is actually normal behavior in some cases. Google’s Credential Manager returns numeric IDs for certain account types - especially Google Workspace accounts or personal accounts with enhanced privacy settings turned on. The docs say you’ll usually get an email, but they don’t promise it every time. I ran into this exact issue when testing with my work account vs. my personal Gmail. What saved me was pulling the email straight from the GoogleIdTokenCredential object using credential.displayName or just parsing the JWT token payload. The numeric ID still works fine as a unique identifier for backend auth, so your flow should handle both formats. I’d suggest adding a fallback that checks if the credential ID has an @ symbol - that way you know which format you’re dealing with.
this happens all the time - it’s not a bug. google returns numeric IDs when accounts have privacy restrictions turned on or when it’s a workspace/enterprise account with strict policies. the email’s prob still in the JWT token though. try decoding the idToken and grab the email claim from there instead of using credential.getId().