title: receive sms from my application in android from special number
body: <p>I want my program to be able to receive sms from a special number("+9856874236"). But, if the SMS is from any other number, it should go to the phone's message inbox and not to my application.</p>
  
  <p>please help me my dears</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.util.Log;
  
  public class receiver extends BroadcastReceiver {
        public String str = "";
  
          @Override
          public void onReceive(Context context, Intent intent) {
              // ---get the SMS message passed in---
  
              Bundle bundle = intent.getExtras();
              SmsMessage[] msgs = null;
  
              if (bundle != null) {
  
                  Object[] pdus = (Object[]) bundle.get("pdus");
                  msgs = new SmsMessage[pdus.length];
  
                  for (int i = 0; i &lt; msgs.length; i++) 
                  {
                      msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
  
                      //for get sms from special number===============================
                      String msg_from = msgs[i].getOriginatingAddress();
                      Log.v("msg_from &gt;&gt;",msg_from);     
                      if(msg_from.equals("+9830007546"))
                      {
                          //===============================
                      str += "SMS from " + msgs[i].getOriginatingAddress();
                      str += " :";
                      str += msgs[i].getMessageBody().toString();
                      str += "\n";    
                      Intent act = new Intent(context, ReceiveSMS.class);
                      act.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                      act.putExtra("message", str);
                      context.startActivity(act);
  
                      this.abortBroadcast();
                      }
  
                  }
                  // ---display the new SMS message---
                  // Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
              }
  
              }
      }
  </code></pre>
  
  <p>main class : </p>
  
  <pre><code>     private TextView showSms;
   private String   ReceivedSms;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
      //this.setContentView(R.layout.receivesms);
       /*Removing system bar from screen*/
      this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(R.layout.receivesms);
      Intent act = getIntent();       
      ReceivedSms = act.getStringExtra("message");
      showSms = (TextView) this.findViewById(R.id.textView2);
      showSms.setText(ReceivedSms);
  </code></pre>