Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smsManager.sendTextMessage is not working

Tags:

android

sms

I have the below event to send sms programatically. However is doens't seem to work, the toast pop up appears and there is no entry in logcat, just no message is created. I have also added the appropriate permissions to manifest file.

Any suggetsions?

 private Runnable SMSRunnable = new Runnable()
 {
     public void run()
     {      
         smsManager = SmsManager.getDefault();

        smsNumber = edittextSmsNumber.getText().toString();
        smsText = edittextSmsText.getText().toString();


        smsManager.sendTextMessage(smsNumber, smsNumber, smsNumber , null, null);

     }
 };
like image 969
Rhys Avatar asked May 25 '12 10:05

Rhys


People also ask

How to Send SMS using SmsManager?

Android Send SMS using SMSManager APISmsManager smgr = SmsManager. getDefault(); smgr. sendTextMessage(MobileNumber,null,Message,null,null);

How to Send SMS in Android application?

icon from the toolbar. Before starting your application, Android studio installer will display following window to select an option where you want to run your Android application. Now you can enter a desired mobile number and a text message to be sent on that number. Finally click on Send SMS button to send your SMS.

How to use SMS manager in Android?

Manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method getDefault() . To create an instance of SmsManager associated with a specific subscription ID, call getSmsManagerForSubscriptionId(int) .


2 Answers

I spent lots of time then I figured out that I could just prepend the country code. For me prepending "+91" before the phone number worked like a champ.

String phnNumber="+91"+editText.getText().toString();
like image 120
Justcurious Avatar answered Nov 15 '22 20:11

Justcurious


Try this.

SmsManager sms = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";

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

sms.sendTextMessage(phoneNumber, null, message, sentPI, null);
like image 28
Raghu Nagaraju Avatar answered Nov 15 '22 19:11

Raghu Nagaraju