Skip to content

Instantly share code, notes, and snippets.

@nguyendung17
Created July 17, 2018 15:43
Show Gist options
  • Save nguyendung17/808d4bd64944f7e0cd32aff10701d77f to your computer and use it in GitHub Desktop.
Save nguyendung17/808d4bd64944f7e0cd32aff10701d77f to your computer and use it in GitHub Desktop.
//If you're targeting API 22 or higher. You can use the following code to get the list of SIM Cards. You can also allow user to choose the SIM Card:
final ArrayList<Integer> simCardList = new ArrayList<>();
SubscriptionManager subscriptionManager;
subscriptionManager = SubscriptionManager.from(activity);
final List<SubscriptionInfo> subscriptionInfoList = subscriptionManager
.getActiveSubscriptionInfoList();
for (SubscriptionInfo subscriptionInfo : subscriptionInfoList) {
int subscriptionId = subscriptionInfo.getSubscriptionId();
simCardList.add(subscriptionId);
}
//Finally send the SMS using following code:
int smsToSendFrom = simCardList.get(0); //assign your desired sim to send sms, or user selected choice
SmsManager.getSmsManagerForSubscriptionId(smsToSendFrom).sendTextMessage(phoneNumber, null, msg, null, null); //use your phone number, message and pending intents
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment