title: How to Monitor Incoming SMS in Android API <19 & API >=19?
body: <p>Am try to Monitoring Incoming SMS in my App. From Android Side they done some change for Monitoring incoming SMS from <strong>API 19</strong>. </p>
  
  <p>Can't Track incoming Message in Background(at the time of App not in Background &amp; Mobile Screen in Off State) in <strong>API 23</strong>. </p>
  
  <p>In Android Document said Can't Track Incoming SMS in Background if your app is not as a Default Message App From <strong>API 19</strong>.</p>
  
  <p>Ref:- <a href="https://android-developers.googleblog.com/2013/10/getting-your-sms-apps-ready-for-kitkat.html" rel="nofollow noreferrer">Getting Your SMS Apps Ready for KitKat </a></p>
  
  <p>But its working on My <strong>API 21(LOLLIPOP)</strong> device. It will not working on <strong>API 23(Marshmallow)</strong> devices. When Devices Screen is on or the app is open means it Working in <strong>API 23(Marshmallow)</strong> also.</p>
  
  <p>Can You Please Update Me Is there any Way to Track Incoming Message in Background in <strong>API 23(Marshmallow)</strong>.</p>
  
  <p><strong>Manifest Code</strong></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_SMS" /&gt;
  
  &lt;receiver
          android:name=".SMSReceiver"
          android:enabled="true"
          android:exported="true"
          android:permission="android.permission.BROADCAST_SMS"&gt;
          &lt;intent-filter android:priority="5822"&gt;
              &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt;
          &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p><strong>Here My Java Code</strong></p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Build;
  import android.os.Bundle;
  import android.telephony.SmsMessage;
  
  public class SMSReceiver extends BroadcastReceiver {
  
  public static final String BROADCAST = "SMS_RECEIVER";
  private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
  
  Intent broadcast_intent;
  String message_body = "", originAddress;
  
  StringBuilder bodyText;
  
  @Override
  public void onReceive(Context context, Intent intent) {
  
  
      if (intent.getAction().equalsIgnoreCase(SMS_RECEIVED)) {
  
          broadcast_intent = new Intent(BROADCAST);
  
          Bundle bundle = intent.getExtras();
          SmsMessage[] messages;
  
          if (bundle != null) {
  
              Object[] pdus = (Object[]) bundle.get("pdus");
  
              messages = new SmsMessage[pdus.length];
  
              bodyText = new StringBuilder();
  
              for (int i = 0; i &lt; messages.length; i++) {
  
                  if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.M) {
                      String format = bundle.getString("format");
                      messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
                  } else {
                      messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                  }
  
                  originAddress = messages[i].getOriginatingAddress().toUpperCase();
                  bodyText.append(messages[i].getMessageBody());
  
              }
  
              message_body = bodyText.toString();
  
          }
      }
  }
  }
  </code></pre>