title: Broadcast Receiver not working in Oppo,Mi and some other phones when application is closed
body: <p>I am trying to detect incoming sms, for that I have created Broadcast Receiver to listen to the incoming sms.
  It works perfectly when the app is in the Foreground.But when I close the app from the recent apps then on some phones like <strong>Oppo and xiaomi</strong> the <strong>Receiver stopped working</strong> and is killed.</p>
  
  <p>Below is the code I have implemented:</p>
  
  <p><strong>SmsReceiver.java</strong></p>
  
  <pre><code>   public class SmsReceiver extends BroadcastReceiver {
  
      SmsMessage currentMessage;
  
      public SmsReceiver() {
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          Toast.makeText(context, " reciever called ", Toast.LENGTH_SHORT).show();
  
          Bundle data = intent.getExtras();
  
          Object[] pdus = (Object[]) data.get("pdus");
          for (int i = 0; i &lt; pdus.length; i++) {
              //SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
              if (android.os.Build.VERSION.SDK_INT &gt;= android.os.Build.VERSION_CODES.M) {
                  currentMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
              } else {
                  currentMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
              }
  
              String sender = currentMessage.getDisplayOriginatingAddress();
  
              if (sender.contains("HP-CRAZND")) {
  
                  String messageBody = currentMessage.getMessageBody();
  
                  if (messageBody.toString() != null || !messageBody.toString().isEmpty()) {
                      Intent ii = new Intent(context, MyService.class);
  
                      ii.putExtra("s", sender);
                      ii.putExtra("m", messageBody);
                      context.startService(ii);
                  }
              }
          }
  
  
      }
  
  }
  </code></pre>
  
  <p><strong>AndroidManifest.xml</strong>:</p>
  
  <p>I have added the receiver as below</p>
  
  <pre><code>           &lt;receiver
                  android:name="saiinfotech.sms.SmsReceiver"&gt;
                  &lt;intent-filter android:priority="100"&gt;
                      &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt;
                  &lt;/intent-filter&gt;
              &lt;/receiver&gt;
  </code></pre>