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

时间:2014-03-25 10:58:34

标签: android sms dual-sim

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

2 个答案:

答案 0 :(得分: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);

答案 1 :(得分:-1)

您可以在MTK平台中使用

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