title: Cannot get OTP when use Sms Retriever
body: <p>I'm trying to use Google's SMS Retriever API for Automatic SMS Verification. I have followed the directions <a href="https://developers.google.com/identity/sms-retriever/request" rel="nofollow noreferrer">here</a> but my app is not receiving any SMS messages. I've tried many ways but it's still not working and I really don't understand why. </p>
  
  <p>Here is what I've done. First I create class <code>MySMSBroadcastReceiver</code>:</p>
  
  <pre><code>public class MySMSBroadcastReceiver extends BroadcastReceiver {
  
      public OTPReceiveListener otpReceiveListener;
      public void initOtpReceiveListener(OTPReceiveListener otpReceiveListener) {
          this.otpReceiveListener = otpReceiveListener;
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
              Bundle extras = intent.getExtras();
              Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);
  
              switch(status.getStatusCode()) {
                  case CommonStatusCodes.SUCCESS:
                      // Get SMS message contents
                      String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
                      otpReceiveListener.onOTPReceived(message);
                      break;
                  case CommonStatusCodes.TIMEOUT:
                      otpReceiveListener.onOTPTimeOut();
                      break;
              }
          }
      }
  
      public interface OTPReceiveListener {
  
          void onOTPReceived(String otp);
          void onOTPTimeOut();
      }
  
  }
  </code></pre>
  
  <p>For class <code>OTPActivity</code>, I remove unrelated code:</p>
  
  <pre><code>public class OTPActivity extends BaseActivity implements IDelegateResponse&lt;OTPResponse&gt;, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, MySMSBroadcastReceiver.OTPReceiveListener {
  
      @BindView(R.id.edtSmsOtp)
      EditText edtSmsOtp;
  
      private final String TAG = "OTPActivity";
      private MySMSBroadcastReceiver mySMSBroadcastReceiver;
  
      @Override
      public int getLayoutID() {
          return R.layout.activity_otp;
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setUpOTPSms();
      }
  
      private void setUpOTPSms() {
          AppSignatureHelper appSignatureHelper = new AppSignatureHelper(OTPActivity.this);
          Utils.showLog(TAG, "getAppSignatures:" + appSignatureHelper.getAppSignatures());
  
          mySMSBroadcastReceiver = new MySMSBroadcastReceiver();
          mySMSBroadcastReceiver.initOtpReceiveListener(this);
  
          IntentFilter intentFilter = new IntentFilter();
          intentFilter.addAction(SmsRetriever.SMS_RETRIEVED_ACTION);
          intentFilter.setPriority(2147483647);
          registerReceiver(mySMSBroadcastReceiver, intentFilter);
  
          startSMSListener();
     }
  
      private void startSMSListener() {
          SmsRetrieverClient client = SmsRetriever.getClient(OTPActivity.this);
          Task&lt;Void&gt; task = client.startSmsRetriever();
          task.addOnSuccessListener(aVoid -&gt; {
              //Toast.makeText(OTPActivity.this, "SMS Retriever starts", Toast.LENGTH_LONG).show();
              Utils.showLog(TAG, "SMS Retriever starts");
          });
          task.addOnFailureListener(e -&gt; Toast.makeText(OTPActivity.this, "Error", Toast.LENGTH_LONG).show());
      }
  
      @Override
      public void onConnected(@Nullable Bundle bundle) {
  
      }
  
      @Override
      public void onConnectionSuspended(int i) {
  
      }
  
      @Override
      public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
  
      }
  
      @Override
      public void onOTPReceived(String otp) {
          if (mySMSBroadcastReceiver != null) {
              unregisterReceiver(mySMSBroadcastReceiver);
          }
  
          Utils.showLog("OTP Received", "OTP: " + otp);
      }
  
      @Override
      public void onOTPTimeOut() {
          Utils.showLog("OTP Received", "onOTPTimeOut");
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          if (mySMSBroadcastReceiver != null) {
              unregisterReceiver(mySMSBroadcastReceiver);
          }
      }
  }
  </code></pre>