title: Read and display incoming message text android
body: <p>I am new to android development.I am developing small android application. In my application I want to retrieve newly coming sms and display this message to user. My code looks like</p>
  
  <pre><code>// HellowordActivity.java
  package com.example.helloword;
  
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.app.Activity;
  import android.os.Bundle;
  import android.telephony.SmsMessage;
  import android.util.Log;
  import android.widget.Toast;
  
  public class HellowordActivity extends BroadcastReceiver
  {
      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().toString();
              strMessage += "\n";
          }
           // Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();
  
          Intent _intent = new Intent(context, PopupActivity.class);
          _intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
          _intent.putExtra("strMessage", strMessage);
          startActivity(_intent);
         }
      }
  
    }  
  </code></pre>
  
  <p>I added receiver and permission in Android Manifest.xml </p>
  
  <p></p>
  
  <pre><code>    &lt;uses-permission android:name="android.permission.RECEIVE_SMS"/&gt;
  
        &lt;receiver android:name=".HellowordActivity" &gt;
                  &lt;intent-filter &gt; 
                  &lt;action android:name="android.provider.Telephony.SMS_RECEIVED"/&gt; 
                  &lt;/intent-filter&gt; 
          &lt;/receiver&gt; 
  &lt;activity android:name=".PopupActivity" android:launchMode="singleTop" /&gt;
  </code></pre>
  
  <p>I am not doing any thing in layout part.What I want as an output when new message will come;
  message text display to user with simple popup.
  Need Help.. Thank you...</p>