title: Huawei auto read sms
body: <p>I want to implement auto read sms in Huawei. I referenced this <a href="https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/readsmsmanager-0000001050050861-V5" rel="nofollow noreferrer">https://developer.huawei.com/consumer/en/doc/development/HMSCore-Guides-V5/readsmsmanager-0000001050050861-V5</a>
  and setup everything as required. But broadcast not working. Here is the code.</p>
  <p>Manifest service declaration</p>
  <pre><code>&lt;receiver
      android:name=&quot;.util.SMSBroadCastReceiver&quot;
      android:exported=&quot;true&quot;&gt;
      &lt;intent-filter&gt;
          &lt;action android:name=&quot;com.huawei.hms.support.sms.common.ReadSmsConstant.READ_SMS_BROADCAST_ACTION&quot; /&gt;
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  <p>Broadcast class</p>
  <pre><code>public class SMSBroadCastReceiver extends BroadcastReceiver {
  
      private static final String TAG = &quot;SMSBroadCastReceiver&quot;;
      private OTPReceiveListener otpReceiver = null;
  
      public void initOTPListener(OTPReceiveListener receiver) {
          this.otpReceiver = receiver;
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Bundle bundle = intent.getExtras();
          if (bundle != null &amp;&amp; ReadSmsConstant.READ_SMS_BROADCAST_ACTION.equals(intent.getAction())) {
              Status status = bundle.getParcelable(ReadSmsConstant.EXTRA_STATUS);
              if (status.getStatusCode() == CommonStatusCodes.TIMEOUT) {
                  // The service has timed out and no SMS message that meets the requirements is read. The service process ends.
                  Log.i(TAG, &quot;onReceive: TIMEOUT &quot;);
                  this.otpReceiver.onOTPTimeOut();
              } else if (status.getStatusCode() == CommonStatusCodes.SUCCESS) {
                  if (bundle.containsKey(ReadSmsConstant.EXTRA_SMS_MESSAGE)) {
                      // An SMS message that meets the requirement is read. The service process ends.
                      Log.i(TAG, &quot;onReceive: received &quot; + bundle.getString(ReadSmsConstant.EXTRA_SMS_MESSAGE));
                      this.otpReceiver.onOTPReceived(bundle.getString(ReadSmsConstant.EXTRA_SMS_MESSAGE));
                  }
              }
          }
      }
  
      public void startSmsRetriever(Context context) {
          Task&lt;Void&gt; task = ReadSmsManager.start(context);
          task.addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
              @Override
              public void onComplete(Task&lt;Void&gt; task) {
                  if (task.isSuccessful()) {
                      // The service is enabled successfully. Perform other operations as needed.
  //                    doSomethingWhenTaskSuccess();
                      Log.i(TAG, &quot;startSmsRetriever: isSuccessful&quot;);
                  }else{
                      //task false
                      Log.i(TAG, &quot;startSmsRetriever: failed&quot;);
                  }
              }
          });
      }
  
      public interface OTPReceiveListener {
  
          void onOTPReceived(String otp);
  
          void onOTPTimeOut();
      }
  }
  </code></pre>
  <p>Activity class codes</p>
  <pre><code>protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          
          smsBroadcast = new SMSBroadCastReceiver();
          smsBroadcast.initOTPListener(this);
          smsBroadcast.startSmsRetriever(this);
      }
  
  
      @Override
      public void onResume() {
          super.onResume();
          IntentFilter intentFilter = new IntentFilter();
          intentFilter.addAction(ReadSmsConstant.READ_SMS_BROADCAST_ACTION);
          registerReceiver(smsBroadcast, intentFilter);
      }
  
      @Override
      public void onPause() {
          unregisterReceiver(smsBroadcast);
          super.onPause();
      }
      
  </code></pre>
  <p>I also generated required hashcode and send the sms.</p>
  <p>Here startSmsRetriever: isSuccessful. But broadcast onReceive not called.
  Please help me on this</p>