Try the following method where simIndex
is 0
for sim1
and 1
for sim2
:
public void sendSMS(final String number,final String text)
{
final PendingIntent localPendingIntent1 = PendingIntent.getBroadcast(mContext, 0, new Intent(this.SENT), 0);
final PendingIntent localPendingIntent2 = PendingIntent.getBroadcast(mContext, 0, new Intent(this.DELIVERED), 0);
if (Build.VERSION.SDK_INT >= 22)
{
SubscriptionManager subscriptionManager=((Activity)mContext).getSystemService(SubscriptionManager.class);
SubscriptionInfo subscriptionInfo=subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(simIndex);
SmsManager.getSmsManagerForSubscriptionId(subscriptionInfo.getSubscriptionId()).sendTextMessage(number, null, text, localPendingIntent1, localPendingIntent2);
}
SmsManager.getSmsManagerForSubscriptionId(subscriptionInfo.getSubscriptionId()).sendTextMessage(number, null, text, localPendingIntent1, localPendingIntent2);
}
3
solved Android send sms in Dual SIM Phone