To send sms programmatically I am using,
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(toNumber, null, text, PendingIntent.getBroadcast(
this, 0, new Intent(SMS_SENT_ACTION), 0), null);
I have coded for api >=22 like,
SubscriptionManager subscriptionManager=(SubscriptionManager)getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subscriptionInfoList=subscriptionManager.getActiveSubscriptionInfoList();
if(subscriptionInfoList!=null && subscriptionInfoList.size()>0){
for(SubscriptionInfo info:subscriptionInfoList){
String mobileNo=info.getNumber();
}
}
using subscription manager I am not getting sim 2 card number using info.getNumber();. It returns empty for Samsung j5 device.
Another important thing is, using SubscriptionManager I am getting line 1 number correctly but empty for line 2. But at the same time when I am trying to send sms using SmsManager.getDefault() it sends sms from line 2. In that device line 2 sim card is set as default.
But based on operators available in a dual sim device toNumber (the number to send sms) will be changed. Because of this I need to know operator name or sim card number of default sim of the device set by user to the number SmsManager.getDefault(). How can I get it know?
To sum everything up, it seems there may be a bug in the Samsung J5 implementation of the dual SIM on Android 23 (resulting in a blank phone number in the SIM settings).