Reputation: 45
I'm creating an android application which makes a call and sends SMS messages, but I don't want to ask the user each time to choose one SIM to send SMS messages through it, so I want to ask the user to enter his phone number (number of one SIM) and make it default to make a call and send SMS in this application without asking him again to choose which SIM he wants. so How can I do that?
Upvotes: 0
Views: 911
Reputation: 567
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager subs = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
if (subs != null) {
Log.d("sim_spalsh", "num sims = " + subs.getActiveSubscriptionInfoCountMax());
if (subs.getActiveSubscriptionInfoCountMax() > 1) {
//SendSMS From SIM One
SmsManager.getSmsManagerForSubscriptionId(0)
.sendTextMessage(phonenumber, null, "sim1", null, null);
//SendSMS From SIM Two
SmsManager.getSmsManagerForSubscriptionId(1)
.sendTextMessage(phonenumber, null, "sim2", null, null);
}
}
}
Give permission
<uses-permission android:name="android.permission.SEND_SMS"/>
Upvotes: 3