SmsCodeAutofillClient

public interface SmsCodeAutofillClient implements HasApiKey<Api.ApiOptions.NoOptions>

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

abstract Task<Integer>
checkPermissionState()
Returns the SmsCodeAutofillClient.PermissionState of the current user-designated autofill service.
abstract Task<Boolean>
hasOngoingSmsRequest(String packageName)
Returns true if there are requests from SmsRetriever in progress for the given package name.
abstract Task<Void>
startSmsCodeRetriever()
Starts SmsCodeRetriever, which looks for an SMS verification code from messages recently received (up to 1 minute prior).

Public Methods

public abstract Task<Integer> checkPermissionState ()

Returns the SmsCodeAutofillClient.PermissionState of the current user-designated autofill service. The result could be NONE, 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 abstract Task<Boolean> hasOngoingSmsRequest (String packageName)

Returns true if there are requests from SmsRetriever 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 through SmsRetriever.

Note: This result does not include those requests from SmsCodeAutofillClient.

public abstract Task<Void> startSmsCodeRetriever ()

Starts SmsCodeRetriever, 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 a String, and EXTRA_STATUS for Status to indicate RESULT_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.