Created
July 17, 2018 15:43
-
-
Save nguyendung17/808d4bd64944f7e0cd32aff10701d77f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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