SmsManager does not send sms

I tried to send an SMS using SMS Manager. I have sufficient permissions. And I went through some answers given in Stackoverflow. This is my code. It works on my phone but doesnt send the SMS. ‘SMS Sent is shown’ Help me. Thank in advance

package com.example.esms;

import android.app.Activity;
import android.os.Bundle;

import android.telephony.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    final EditText textName = (EditText) findViewById(R.id.editText1);
    final EditText textPhone = (EditText) findViewById(R.id.editText2);
    Button buttonSend = (Button) findViewById(R.id.button1);

    buttonSend.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            try {
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(textPhone.toString(), null, textName.toString(), null, null);
                Toast.makeText(getApplicationContext(), "SMS Sent!",
                        Toast.LENGTH_LONG).show();
            } catch (Exception e) {
                Toast.makeText(getApplicationContext(),
                        "SMS faild, please try again later!",
                        Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }   
        }
    });


}
}


Source: eclipse

Leave a Reply