title: How to receive new incoming message in android?
body: <ul>
  <li><p>I have tried and searched a lot and implemented also but i am not getting result. As soon as new SMS message comes, I am trying to display on toast by using Broadcast Receiver. But, not giving result.</p></li>
  <li><p>I am trying with this code,</p></li>
  <li><p>BroadcastReceiver class</p>
  
  <pre><code>public class MainActivity extends BroadcastReceiver{
  @SuppressLint("NewApi")
  @Override
  
      public void onReceive(Context context, Intent intent) {
          Bundle myBundle = intent.getExtras();
          SmsMessage [] messages = null;
          String strMessage = "";
          if (myBundle != null)
          {
              Object [] pdus = (Object[]) myBundle.get("pdus");
              messages = new SmsMessage[pdus.length];
              for (int i = 0; i &lt; messages.length; i++)
              {
                  messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                  strMessage += "SMS From: " + messages[i].getOriginatingAddress();
                  strMessage += " : ";
                  strMessage += messages[i].getMessageBody();
                  strMessage += "\n";
              }
              Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();
          }
      }
  }
  </code></pre></li>
  <li><p>manifest.xml</p>
  
  <pre><code> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.websoftexmessagetracker"
      android:versionCode="1"
      android:versionName="1.0" &gt;
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="19" /&gt;
      &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;receiver android:name=".MainActivity" &gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.provider.Telephony.SMS_RECEIVED" /&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
      &lt;/application&gt;
  &lt;/manifest&gt;
  </code></pre></li>
  </ul>
  
  <p>please help me to sort out this issue. I am not getting that what is required again so that it will work..
  Thanks in advance..
  please help me anyone...</p>