SmsRetriever

public final class SmsRetriever extends Object

The SmsRetriever API provides access to Google services that help you retrieve the SMS message directed to your app without asking for android.permission.READ_SMS.

To use SmsRetriever, obtain an instance of SmsRetrieverClient using getClient(Context) or getClient(Activity), and start SMS retriever service by calling startSmsRetriever(). The service waits for ONE matching SMS message until timeout (5 minutes).

The received SMS message will be sent via a Broadcast Intent with action SmsRetriever.SMS_RETRIEVED_ACTION. The Intent contains Extras with keys SmsRetriever.EXTRA_SMS_MESSAGE for the retrieved SMS message as a String, and SmsRetriever.EXTRA_STATUS for Status to indicate SUCCESS, DEVELOPER_ERROR, ERROR, or TIMEOUT.

The possible causes for errors are:

  • DEVELOPER_ERROR: the caller app has incorrect number of certificates. Only one certificate is allowed.
  • ERROR: the AppCode collides with other installed apps.

Constant Summary

String EXTRA_SMS_MESSAGE Intent extra key of the retrieved SMS message as a String
String EXTRA_STATUS Intent extra key of Status, which indicates SUCCESS or TIMEOUT
String SMS_RETRIEVED_ACTION Intent action when SMS message is retrieved.

Public Method Summary

static SmsRetrieverClient
getClient(Activity activity)
Create a new instance of SmsRetrieverClient for use in an Activity.
static SmsRetrieverClient
getClient(Context context)
Create a new instance of SmsRetrieverClient for use in an Context.

Inherited Method Summary

Constants

public static final String EXTRA_SMS_MESSAGE

Intent extra key of the retrieved SMS message as a String

Constant Value: "com.google.android.gms.auth.api.phone.EXTRA_SMS_MESSAGE"

public static final String EXTRA_STATUS

Intent extra key of Status, which indicates SUCCESS or TIMEOUT

Constant Value: "com.google.android.gms.auth.api.phone.EXTRA_STATUS"

public static final String SMS_RETRIEVED_ACTION

Intent action when SMS message is retrieved.

Constant Value: "com.google.android.gms.auth.api.phone.SMS_RETRIEVED"

Public Methods

public static SmsRetrieverClient getClient (Activity activity)

Create a new instance of SmsRetrieverClient for use in an Activity.

public static SmsRetrieverClient getClient (Context context)

Create a new instance of SmsRetrieverClient for use in an Context.