The interface for interacting with the SMS Code Browser API. By using
startSmsCodeRetriever(), you can retrieve the origin-bound one-time code from SMS
messages.
The SMS message format should follow the origin-bound one-time code specification:
Here is an example:
747723 is your ExampleCo authentication code. @example.com #747723
Note: This interface works only for the default browser app set by the current
user. Any other calls will fail with
SmsRetrieverStatusCodes.API_NOT_AVAILABLE.
| abstract Task<Void> |
startSmsCodeRetriever()
Starts
SmsCodeRetriever, which looks for an origin-bound one-time code
from SMS messages recently received (up to 1 minute prior).
|
Starts SmsCodeRetriever, which looks for an origin-bound one-time code from SMS
messages recently received (up to 1 minute prior). If there is no matching message
found from the SMS inbox, it waits for new incoming SMS messages until it finds a
matching message or reaches the timeout (about 5 minutes). Calling this method multiple
times only returns one result, but it can extend the timeout period to the last call.
Once the result is returned or it reaches the timeout, SmsCodeRetriever
will stop automatically.
The SMS verification code will be sent via a Broadcast Intent with
SmsCodeRetriever.SMS_CODE_RETRIEVED_ACTION. This Intent contains Extras with
keys:
SmsCodeRetriever.EXTRA_SMS_CODE_LINE for the retrieved line that contains
the origin-bound one-time code and the metadata, or null in failed
cases.
SmsCodeRetriever.EXTRA_STATUS for the Status
to indicate RESULT_SUCCESS, RESULT_TIMEOUT or other
SmsRetrieverStatusCodes.If the caller has not been granted or denied permission by the user, it will fail
with a ResolvableApiException.
The caller can use
ResolvableApiException.startResolutionForResult(Activity, int) to show a
consent dialog for requesting permission from the user. The dialog result is returned
via
Activity.onActivityResult(int, int, Intent). If the user grants the
permission, the activity result returns with RESULT_OK. Then you can start
the retriever again to retrieve the verification code.
Note: Add
SmsRetriever.SEND_PERMISSION in
Context.registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
while registering the receiver to detect that the broadcast intent is from the SMS
Retriever.