The interface for interacting with the SMS Code Autofill API. These methods are only
supported on devices running Android P and later. For devices that run versions earlier than
Android P, all method calls return
PLATFORM_NOT_SUPPORTED
.
Note:This interface works only for the current user-designated autofill service.
Any calls from non user-designated autofill services or other applications will fail with
API_NOT_AVAILABLE
.
Nested Class Summary
@interface | SmsCodeAutofillClient.PermissionState | Permission states for the current user-designated autofill service. |
Public Method Summary
abstractTask<Integer> |
checkPermissionState()
Returns the
SmsCodeAutofillClient.PermissionState of the current user-designated
autofill service.
|
abstractTask<Boolean> |
hasOngoingSmsRequest(StringpackageName)
Returns
true if there are requests fromSmsRetriever
in progress for the given package name.
|
abstractTask<Void> |
startSmsCodeRetriever()
Starts
SmsCodeRetriever ,which looks for an SMS verification code
from messages recently received (up to 1 minute prior).
|
Public Methods
public abstractTask<Integer> checkPermissionState()
Returns the
SmsCodeAutofillClient.PermissionState
of the current user-designated
autofill service. The result could beNONE
,GRANTED
,or
DENIED
.
The autofill service should check its permission state prior to showing the
suggestion prompt for retrieving an SMS verification code, because it will definitely
fail on calling
startSmsCodeRetriever()
in permission denied state.
public abstractTask<Boolean> hasOngoingSmsRequest(String packageName)
Returnstrue
if there are requests fromSmsRetriever
in progress for the given package name.
The autofill service can check this method to avoid showing a suggestion prompt for
retrieving an SMS verification code, in case that a user app may already be retrieving
the SMS verification code throughSmsRetriever
.
Note:This result does not include those requests from
SmsCodeAutofillClient
.
public abstractTask<Void>startSmsCodeRetriever()
StartsSmsCodeRetriever
,which looks for an SMS verification code from
messages recently received (up to 1 minute prior). If there is no SMS verification code
found from the SMS inbox, it waits for new incoming SMS messages until it finds an SMS
verification code or reaches the timeout (about 5 minutes).
The SMS verification code will be sent via a Broadcast Intent with
SMS_CODE_RETRIEVED_ACTION
.This Intent contains Extras with keys
EXTRA_SMS_CODE
for the retrieved verification code as aString
,
and
EXTRA_STATUS
forStatus
to
indicateRESULT_SUCCESS
,RESULT_TIMEOUT
or
SmsRetrieverStatusCodes
.
Note:Add
SEND_PERMISSION
in
registerReceiver(BroadcastReceiver, IntentFilter, String, Handler)
while
registering the receiver to detect that the broadcast intent is from the SMS Retriever.
Be aware that this detection only works on devices using Google Play services v19.8.31
and later.