SmsManager.sendTextMessage not working

I have the following event for sending sms programmatically. However, doens't seem to be working, a toast appears, and there is no entry in logcat, just a message is not created. I also added appropriate permissions for the manifest file.

Any suggestions?

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); } }; 
+7
source share
4 answers

Try it.

 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); 
+9
source

This is what works for me:

 PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, Next.class), 0); //Next is the class to move when message sent SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage("phno", null, "message", null, null); 
+1
source

I spent a lot of time, then I realized that I can just add the country code. For me, adding β€œ+91” before the phone number worked like a champion.

 String phnNumber="+91"+editText.getText().toString(); 
+1
source

This actually works for me:

 String messageText = "...YOUR TEXT HERE..."; SmsManager sm = SmsManager.getDefault(); sm.sendTextMessage("PHONE NUMBER HERE", null, messageText, null, null); 

To be sure, with this you will not find a message sent to the message history.

0
source

All Articles