I am stuck for a long time and can't solve it. Please help... I am trying to send sms programmatically from android device. I can send successfully from many devices but can't from some Samsung dual sim devices with android api level >=22. For api level >=22 I have coded like,
public static final String SMS_SENT_ACTION = "package.name.app.SMS_SENT_ACTION";
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
unregisterReceiver(this);
String message = null;
switch (getResultCode()) {
case Activity.RESULT_OK:
message = "Message Sent Successfully !";
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
message = "Error.";
sendDefaultMessage(default_number, default_send_number, text);
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
message = "Error: No service.";
sendDefaultMessage(default_number, default_send_number, text);
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
message = "Error: Null PDU.";
sendDefaultMessage(default_number, default_send_number, text);
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
message = "Error: Radio off.";
sendDefaultMessage(default_number, default_send_number, text);
break;
}
Toast.makeText(GetAppointment.this, message, Toast.LENGTH_LONG).show();
}
}, new IntentFilter(SMS_SENT_ACTION));
SmsManager.getSmsManagerForSubscriptionId(subscription_id).sendTextMessage(send_number, null, messageToSend, PendingIntent.getBroadcast(
this, 0, new Intent(SMS_SENT_ACTION), 0), null);
There is no permission related issue because sms can be sent from asus dual sim device and sony single sim device with api level >=22.
How can I make it work for all device? I need help badly.
You need to provide service center number of SIM you want to send SMS from in your
sendTextMessage()
as second parameter like,