title: Cannot send sms verification code using with the SMS User Consent API on android
body: <p>I am trying to make a phone number verification on android studio using java. I followed the instructions from the documentation here <a href="https://developers.google.com/identity/sms-retriever/user-consent/overview" rel="nofollow noreferrer">https://developers.google.com/identity/sms-retriever/user-consent/overview</a> but sadly it isn't sending me an SMS code, and I am not getting any error. Below is my code:</p>
  <pre><code>public class OTPSMSActivity extends AppCompatActivity {
      private ImageView blur;
      private TextView resend;
      private CustomEditText editText;
      private FirebaseFirestore db = FirebaseFirestore.getInstance();
      private KProgressHUD loadingBar;
      private static final int SMS_CONSENT_REQUEST = 2;
  
      // Set to an unused request code
      private final BroadcastReceiver smsVerificationReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
                  Bundle extras = intent.getExtras();
                  Status smsRetrieverStatus = (Status) extras.get(SmsRetriever.EXTRA_STATUS);
  
                  switch (smsRetrieverStatus.getStatusCode()) {
                      case CommonStatusCodes.SUCCESS:
                          // Get consent intent
                          Intent consentIntent = extras.getParcelable(SmsRetriever.EXTRA_CONSENT_INTENT);
                          try {
                              /*Start activity to show consent dialog to user within
                               *5 minutes, otherwise you'll receive another TIMEOUT intent
                               */
                              startActivityForResult(consentIntent, SMS_CONSENT_REQUEST);
                              Log.d(&quot;life&quot;, &quot;Intent to send image&quot;);
                          } catch (ActivityNotFoundException e) {
                              Log.e(&quot;life&quot;, &quot;Exception: &quot; + e.toString());
                          }
                          break;
                      case CommonStatusCodes.TIMEOUT:
                          Log.d(&quot;life&quot;, &quot;Timeout!&quot;);
                          break;
                  }
              } else {
                  Log.d(&quot;life&quot;, &quot;SmsRetriever don't matched&quot;);
              }
          }
      };
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_otpsms);
  
          blur = findViewById(R.id.blur);
          editText = findViewById(R.id.number);
          Button verify = findViewById(R.id.verify);
          TextView change = findViewById(R.id.textView42);
          resend = findViewById(R.id.resend);
  
          Paper.init(this);
  
          getBackgroundImage();
  
          change.setOnClickListener(view -&gt; {
              finish();
          });
  
  
          String phoneNumber = getIntent().getStringExtra(&quot;phone&quot;);
  
          loadingBar = KProgressHUD.create(OTPSMSActivity.this)
                  .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                  .setLabel(&quot;Please wait&quot;)
                  .setDetailsLabel(&quot;Sending sms code to your phone number.&quot;)
                  .setCancellable(true)
                  .setAnimationSpeed(2)
                  .setDimAmount(0.5f)
                  .show();
  
          verify.setOnClickListener(view -&gt; {
              loadingBar = KProgressHUD.create(OTPSMSActivity.this)
                      .setStyle(KProgressHUD.Style.SPIN_INDETERMINATE)
                      .setLabel(&quot;Loading&quot;)
                      .setDetailsLabel(&quot;Verifying code&quot;)
                      .setCancellable(true)
                      .setAnimationSpeed(2)
                      .setDimAmount(0.5f)
                      .show();
              String theCode = editText.getText().toString();
              if (theCode.length() != 6){
                  new StyleableToast
                          .Builder(OTPSMSActivity.this)
                          .text(&quot;Invalid code.&quot;)
                          .iconStart(R.drawable.error)
                          .textColor(Color.WHITE)
                          .backgroundColor(getResources().getColor(R.color.error))
                          .show();
                  editText.setError(&quot;Invalid phone number.&quot;);
                  editText.requestFocus();
                  loadingBar.dismiss();
                  return;
              }
              verifyCode(theCode);
          });
  
          resend.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
              }
          });
  
          String phone = &quot;+63&quot; + phoneNumber.substring(1);
          Log.d(&quot;life&quot;, phone);
          Task&lt;Void&gt; task = SmsRetriever.getClient(this).startSmsUserConsent(phone);
  
          task.addOnCompleteListener(listener -&gt; {
              if (listener.isSuccessful()) {
                  Log.d(&quot;life&quot;, &quot;Success&quot;);
                  loadingBar.dismiss();
  
                  IntentFilter intentFilter = new IntentFilter(SmsRetriever.SMS_RETRIEVED_ACTION);
                  registerReceiver(smsVerificationReceiver, intentFilter);
              } else {
                  Exception exception = listener.getException();
                  exception.printStackTrace();
              }
          });
      }
  
      private void verifyCode(String code) {
          if (code.equals(editText.getText().toString())) {
              String phoneNumber = getIntent().getStringExtra(&quot;phone&quot;);
              String userID = Paper.book().read(&quot;userID&quot;);
  
              loadingBar.setDetailsLabel(&quot;Uploading number to database&quot;);
              db.collection(&quot;Buyers&quot;).document(userID)
                      .update(&quot;phone&quot;, &quot;+63&quot; + phoneNumber.substring(1))
                      .addOnCompleteListener(task11 -&gt; {
                          if (task11.isSuccessful()){
                              loadingBar.dismiss();
                              StyleableToast.makeText(OTPSMSActivity.this, &quot;Success! Phone number updated.&quot;, Toast.LENGTH_LONG, R.style.successtoast).show();
                              finish();
                          }
                      });
          } else {
              new StyleableToast
                      .Builder(OTPSMSActivity.this)
                      .text(&quot;Code does not matched.&quot;)
                      .iconStart(R.drawable.error)
                      .textColor(Color.WHITE)
                      .backgroundColor(getResources().getColor(R.color.error))
                      .show();
              loadingBar.dismiss();
          }
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          if (requestCode == SMS_CONSENT_REQUEST) {
              if (resultCode == RESULT_OK) {
                  // Get SMS message content
                  String message = data.getStringExtra(SmsRetriever.EXTRA_SMS_MESSAGE);
                  // Extract one-time code from the message and complete verification
                  String oneTimeCode = parseOneTimeCode(message);
                  Log.d(&quot;life&quot;, &quot;oneTimeCode: &quot; + oneTimeCode);
                  //for this demo we will display it instead
                  editText.setText(oneTimeCode);
              } else {
                  Log.d(&quot;life&quot;, &quot;Error2&quot;);
              }
          } else {
              Log.d(&quot;life&quot;, &quot;Error1&quot;);
          }
      }
  
  
      private String parseOneTimeCode(String message) {
          //simple number extractor
          return message.replaceAll(&quot;[^0-9]&quot;, &quot;&quot;);
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          //to prevent IntentReceiver leakage unregister
          unregisterReceiver(smsVerificationReceiver);
      }
  </code></pre>
  <p>I want to know what am I doing wrong here.</p>