Search code examples
androidfirebasefirebase-authenticationgoogle-apigoogle-one-tap

Android Google One-Tap in Jetpack Compose


I integrated one tap into my app and it was working fine. To do some experimenting, I was clicking the button and then canceling. Now when I click the button, nothing appears on the screen and I get an Exception.

Exception: com.google.android.gms.common.api.ApiException: 16: The caller has been temporarily blocked due to too many canceled sign-in prompts.

How can I solve this problem?

Android Google One-Tap Exception


Solution

  • I was clicking the button and then canceling.

    Yes, you did that too many times. That's indeed the reason why you got that error. In the official documentation and this article, is mentioned that such practices that are performed repeatedly will throw an exception:

    If the user declined to sign in, the call to getSignInCredentialFromIntent() will throw an ApiException with a CommonStatusCodes.CANCELED status code.

    Also in the docs is mentioned that:

    When this happens, you should temporarily disable the One Tap sign-in UI so you don't annoy your users with repeated prompts.

    Since I know that you followed this resource, and you're implementing this in Android, the key to solving this problem lies in the documentation too:

    The following example accomplishes this by setting a property on the Activity, which it uses to determine whether to offer the user One Tap sign-in; however, you could also save a value to SharedPreferences or use some other method.

    It's important to implement your own rate limiting of One Tap sign-in prompts. If you don't, and a user cancels several prompts in a row, the One Tap client will not prompt the user for the next 24 hours.

    So you have to wait 24 hours until this you're whitelisted again.

    However, if you don't want to wait 24 hours, check the note in the docs that says:

    If you encounter this 24-hour cooldown period during development, you can reset the cooldown by clearing Google Play services' app storage. Alternatively, to toggle on/off this cooldown on a test device and/or emulator alike, simply go to the Dialer app and input the following code: ##66382723##. Upon submission, there will be no feedback, but your dialer will clear all input and may close. The cooldown should be toggled off after this. To toggle it back on, input the same code again.