如何在双卡手机中从特定SIM卡发送短信

4

我正在尝试开发一款能够向目标发送短信的Android应用程序。 如果有两张SIM卡(SIM1、SIM2),我该如何检测它们并选择特定的SIM卡来发送短信? 谢谢。


1
可能是双卡Android的重复问题。 - Manoj Kumar
1
请看这里这里 - Manoj Kumar
2个回答

1

请尝试此代码。使用Android sdk 5.1及以上版本。

String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";

PendingIntent localPendingIntent1 = PendingIntent.getBroadcast(mContext, 0, new Intent(this.SENT), 0);
PendingIntent localPendingIntent2 = PendingIntent.getBroadcast(mContext, 0, new Intent(this.DELIVERED), 0);

SubscriptionManager localSubscriptionManager = SubscriptionManager.from(mContext);
if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1)
{
List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
final String[] arrayOfString = new String[localList.size()];
int i = 0;
Iterator localIterator = localList.iterator();
while (localIterator.hasNext())
{
SubscriptionInfo localSubscriptionInfo = (SubscriptionInfo)localIterator.next();
localSubscriptionInfo.getSubscriptionId();
//log.d("22 api level ", "got dual sim: ");
int j = i + 1;
arrayOfString[i] = (localSubscriptionInfo.getCarrierName().toString() + " " + localSubscriptionInfo.getNumber());
i = j;
}

SmsManager.getDefault().sendTextMessage(paramString1, null, paramString2, localPendingIntent1, localPendingIntent2);

请参考以下链接:http://stackoverflow.com/questions/38093754/send-sms-using-sim-selection-option# - harikrishnan
问题是询问如何从特定的SIM卡发送短信,而不是获取有关特定SIM卡的信息! - Choletski

-1

在 MTK 平台上,您可以使用:

SmsManagerEx.getDefault().sendTextMessage(serverAddress, null,
                    textMessage, pendingIntent, null, mSIM);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接