title: How to receive sms in android?
body: <p>I am new to android and i am using android 2.1 for some sms_receive thing: when an sms received,it won't work... Nothing happens when sms received and I have force close, help!</p>
  
  <p><strong>Code for androidmanifest.xml:</strong></p>
  
  <pre><code>&lt;uses-sdk android:minsdkversion="7" /&gt;
  &lt;uses-permission android:name="android.permission.RECEIVE_SMS" /&gt;
  &lt;application android:label="@string/app_name"&gt;
      &lt;activity&gt;
          android:name=".SmsReceiver"
          android:label="@string/app_name"&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;/activity&gt;
      &lt;receiver android:name="com.example.smsreceiver.SmsReceiver" android:enabled="true"&gt;
          &lt;intent-filter android:priority="2147483647"&gt;
              &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Class RSMSActivity:</strong> </p>
  
  <pre><code>public class RSMSActivity extends BroadcastReceiver {
  
      private static final String SHORTCODE = "55443";
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Bundle bundle = intent.getExtras();
          Object[] messages = (Object[]) bundle.get("pdus");
          SmsMessage[] sms = new SmsMessage[messages.length];
          // Create messages for each incoming PDU
          for (int n = 0; n &lt; messages.length; n++) {
              sms[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
          }
          for (SmsMessage msg : sms) {
              // Verify if the message came from our known sender
              if (TextUtils.equals(msg.getOriginatingAddress(), "09358921973")) {
                  Toast.makeText(context, "Received message from the mothership: " + msg.getMessageBody(),
                          Toast.LENGTH_SHORT).show();
              }
          }
      }
  }
  </code></pre>