1

In the following docs: https://developers.google.com/identity/sms-retriever/user-consent/request

it is stated a message triggers the broadcast only if it meets these criteria:

  1. The message contains a 4-10 character alphanumeric string with at
    least one number.
  2. The message was sent by a phone number that's not in the user's contacts.
  3. If you specified the sender's phone number, the message was sent by that number.

However it's not mentioned how to deal with the situation when any of the above criteria is not met and broadcast is not triggered. How do we conduct this to the end-user?

I am able to handle success and timeout cases and handling this situation would make the code more user-friendly.

switch (smsRetrieverStatus.getStatusCode()) {

    case CommonStatusCodes.SUCCESS:                    
        // Get consent intent
        Intent consentIntent = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT);
        try {
            // Start activity to show consent dialog to user, activity must be started in
            // 5 minutes, otherwise you'll receive another TIMEOUT intent
            startActivityForResult(consentIntent, SMS_CONSENT_REQUEST);
        } catch (ActivityNotFoundException e) {
            Log.d("Exception","ActivityNotFound");// Handle the exception ...
        }
        break;

    case CommonStatusCodes.TIMEOUT:
        Log.e("Timeout-Error:","Listened for msg for 5minutes");
            break;
}
Andrew Trubin
  • 143
  • 1
  • 1
  • 11
Shrimantee Roy
  • 317
  • 3
  • 10

1 Answers1

0

You could try using CommonStatusCodes.ERROR but I am not sure if this would get triggered when the SMS received is specifically invalid.

One user-friendly solution may be: setting a timer of 30 seconds for example that starts as soon as you request the SMS/OTP. When the countdown is done, you display a "RESEND SMS" button. So in case the SMS was not received/retrieved, you have a more-user friendly way of letting the user retry and request another SMS.

yalematta
  • 1,389
  • 1
  • 21
  • 36