How to get an incoming SMS' phone number?
<p>How do I get an incoming SMS' phone number?</p>

<p>I wrote <code>BroadcastReciever</code> as in <a href="http://stackoverflow.com/questions/5692659/how-would-i-track-incoming-sms-in-android">this link</a>, but I don't get any output. Also the Toast message in that <code>BroadcastReciever</code> does not get displayed.</p>

<p>Here is another <code>sms.java</code> file for which I used that <code>BroadcastReciever</code>.</p>

<pre><code>public class SMS extends Activity {
    /** Called when the activity is first created. */
    Button btn;
    EditText edt1;
    EditText edt2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        btn=(Button) findViewById(R.id.btn1);
        edt1=(EditText) findViewById(R.id.edt1);
        edt2=(EditText) findViewById(R.id.edt2);

        btn.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String phone=edt1.getText().toString();
                String message=edt2.getText().toString();

                if (phone.length()&gt;0 &amp;&amp; message.length()&gt;0)
                    sendSMS(phone, message);
                else
                    Toast.makeText(getApplicationContext(),
                        "Enter the phone_no &amp; message.", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void sendSMS(String phoneNumber, String message)
    {
        Intent i1 = new Intent(this, SMS.class);
        PendingIntent pi = PendingIntent.getActivity(this, 0,
                                                     i1 , 0);
        SmsManager SMS1 = SmsManager.getDefault();
        SMS1.sendTextMessage(phoneNumber, null, message, pi, null);
    }
}
</code></pre>
