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);
}
};
Android Send SMS using SMSManager APISmsManager smgr = SmsManager. getDefault(); smgr. sendTextMessage(MobileNumber,null,Message,null,null);
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.
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) .
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();
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With