Send SMS from Emulator
<p>I have a webservice, who returns a json SMS object and i want to send it from the Emulator</p>

<p>My Code:</p>

<pre><code>public class WebSMSActivity extends Activity {
    /** Called when the activity is first created. */
    RestConnection con;
    Editor editor;
    int id;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final ToggleButton bt = (ToggleButton)findViewById(R.id.toggleButton1);
        final TextView tvnum = (TextView)findViewById(R.id.textView2);
        final EditText tvtxt = (EditText)findViewById(R.id.editText1);
        final SharedPreferences pref = this.getSharedPreferences("WEBSMS", 0); //Logindata
        editor = pref.edit();


       boolean running = false;
        final Thread t = new Thread(){
            @Override
            public void run() {
                try {


                while (!this.isInterrupted())
                {
                    String s = getStringContent("http://xxx.xx/php/GETSMS.php");
                    Log.e("WEBSMS",s);
                    JSONObject obj = new JSONObject(s);
                    id = obj.getInt("ID");
                    final String nummber = obj.getString("NUMMER");
                    final String txt = obj.getString("TEXT");
                    runOnUiThread(new  Runnable() {
                        public void run() {
                            tvnum.setText(nummber);
                            tvtxt.setText(txt);
                        }
                    });

                    Log.e("WEBSMS",nummber +":"+txt);
                    if(pref.getInt("ID", 1)&gt;id)
                    {
                        sendSMS(nummber, txt);
                    }

                    Log.e("WEBSMS","sleep on");
                    Thread.sleep(3000);
                    Log.e("WEBSMS","sleep off");
                }
                } catch (Exception e) {
                    Log.e("WEBSMS",e.getMessage());

                }

            }
        };

        bt.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if(bt.isChecked())
                    {
                        t.start();

                    }
                    else
                    {
                        t.interrupt();
                    }

                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });



    }
    public static String getStringContent(String uri) throws Exception {

        try {
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet();
            request.setURI(new URI(uri));
            HttpResponse response = client.execute(request);
            InputStream ips  = response.getEntity().getContent();
            BufferedReader buf = new BufferedReader(new InputStreamReader(ips,"UTF-8"));

            StringBuilder sb = new StringBuilder();
            String s;
            while(true )
            {
                s = buf.readLine();
                if(s==null || s.length()==0)
                    break;
                sb.append(s);

            }
            buf.close();
            ips.close();
            return sb.toString();

            } 
        finally {
                   // any cleanup code...
                }
            }

    private void sendSMS(String phoneNumber, String message)
    {        
        String SENT = "SMS_SENT";
        String DELIVERED = "SMS_DELIVERED";

        PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
            new Intent(SENT), 0);

        PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
            new Intent(DELIVERED), 0);

        //---when the SMS has been sent---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS sent", 
                                Toast.LENGTH_SHORT).show();
                        editor.putInt("ID", id);
                        editor.commit();
                        break;
                    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                        Toast.makeText(getBaseContext(), "Generic failure", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NO_SERVICE:
                        Toast.makeText(getBaseContext(), "No service", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_NULL_PDU:
                        Toast.makeText(getBaseContext(), "Null PDU", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case SmsManager.RESULT_ERROR_RADIO_OFF:
                        Toast.makeText(getBaseContext(), "Radio off", 
                                Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        }, new IntentFilter(SENT));

        //---when the SMS has been delivered---
        registerReceiver(new BroadcastReceiver(){
            @Override
            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode())
                {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;
                    case Activity.RESULT_CANCELED:
                        Toast.makeText(getBaseContext(), "SMS not delivered", 
                                Toast.LENGTH_SHORT).show();
                        break;                        
                }
            }
        }, new IntentFilter(DELIVERED));        

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, "06605676542", message, sentPI, deliveredPI);        
    }


}
</code></pre>

<p>LogCat:</p>

<pre><code>04-09 20:21:06.057: E/WEBSMS(1545): {"ID":"10","NUMMER":"5554","TEXT":"eeeeeeeeeeeee"}
04-09 20:21:06.077: E/WEBSMS(1545): 5554:eeeeeeeeeeeee
04-09 20:21:06.077: E/WEBSMS(1545): sleep on
04-09 20:21:09.145: E/WEBSMS(1545): sleep off
</code></pre>

<p>The number is 5554 (the emulator number). I want to send a sms from the emulator to the emulator. Please help. I have tried it on my droid and there i also can't send sms to myself. The permission send_sms and internet is given</p>
