title: Android SMS Broadcast Receiver not working
body: <p>I' m trying to build an app that receives notifications of incoming sms. I need help as incoming SMS's are not detected on any device. I am using the following code that I got from here:</p>
  
  <p><a href="http://karanbalkar.com/2014/09/display-incoming-sms-messages-in-android/" rel="nofollow">http://karanbalkar.com/2014/09/display-incoming-sms-messages-in-android/</a></p>
  
  <pre><code>import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.telephony.SmsMessage;
  import android.widget.Toast;
  
  public class MySMSApp extends BroadcastReceiver {
  
  public static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
  
  @Override
  public void onReceive(Context context, Intent intent) {
      // TODO Auto-generated method stub
      if (intent.getAction().equals(ACTION)){ 
          Bundle bundle = intent.getExtras();
          if (bundle != null){
              Object[] pdus = (Object[]) bundle.get("pdus");
              SmsMessage[] messages = new SmsMessage[pdus.length];
              for (int i = 0; i &lt; pdus.length; i++){
                  messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
              }
              for (SmsMessage message : messages){
  
                  String strMessageFrom = message.getDisplayOriginatingAddress();
                  String strMessageBody = message.getDisplayMessageBody();
  
                  Toast.makeText(context, "SMS Message received from:" +strMessageFrom, Toast.LENGTH_LONG).show();
                  Toast.makeText(context, "SMS Message content" +strMessageBody, Toast.LENGTH_LONG).show();
  
              }
          }    
      } 
  }
  </code></pre>
  
  <p>And the manifest reads as follows. I have setup the intent receiver to trigger the class above but it seems not to do so. I'm unable to telnet onto the emulator to spoof an incoming sms and so I'm blind as to what's going on.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_SMS"/&gt;
  &lt;uses-permission android:name="android.permission.READ_SMS" /&gt;
  
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".MainActivity"
          android:configChanges="orientation|keyboardHidden|screenSize"
          android:label="@string/app_name"
          android:theme="@style/FullscreenTheme" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
          &lt;receiver android:name=".SMSBroadcastReceiver" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" &gt;
                  &lt;/action&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>