用于双人手机的短信管理器?

时间:2013-01-11 10:38:41

标签: android

我正在使用SMS Manager在android中发送短信。我使用的代码如下:

private void sendSms(String Phnno, String Message) {
    if (Utils.checkSIM(MyActivity.this)) {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(Phnno, null, Message, null, null);
        Utils.showMessage(MyActivity.this,"","Thank You for your interest,please check your inbox for the results.");

    } else {
        showErrorMessage(MyActivity.this, "SIM Error!",
                "Please insert SIM");
    }

}

这段代码在单人手机上完全适合我,但当我在双卡手机中检查时,我收到了警告,短信从不发送。

01-11 15:56:13.664: W/sendTextMessage(6656): use single sim interface to sendTextMessage by double sim interface

请建议我如何在我的双卡手机上实现它。谢谢你。

3 个答案:

答案 0 :(得分:8)

这将适用于这两种情况。如果已经选择了已经用户的默认SIM卡,它将自动接受并转到下一个过程,否则当点击发送按钮时,它将询问确认选择任何SIM卡发送短信。我们测试了它的工作正常。

示例源代码:

try 
{    
     Intent sendIntent = new Intent(Intent.ACTION_VIEW);
     sendIntent.putExtra("sms_body","Body");
     sendIntent.putExtra("address", "PhoneNumber");
     sendIntent.setType("vnd.android-dir/mms-sms");
     startActivity(sendIntent);
} 
catch (Exception e) 
{
     Toast.makeText(getApplicationContext(),"SMS faild, please try again later!",Toast.LENGTH_SHORT).show();
     e.printStackTrace();
}

答案 1 :(得分:4)

sendTextMessage()具有scAddress参数。这用于定义SMS中心地址。我想如果你设置正确,你就能发送信息。

您可以按照本教程找到该号码: http://algorithmic-indian.blogspot.hu/2011/03/how-to-change-message-center-number-in.html 您也可以尝试这一点how to get the smsc number of a phone in android?显然似乎没有办法以编程方式获取数字。

答案 2 :(得分:0)

尝试使用此代码选择SIM卡,然后使用SMS发送方法发送短信!

//above Android API 22
if (Build.VERSION.SDK_INT > 22) {
//for dual sim mobile
SubscriptionManager localSubscriptionManager = SubscriptionManager.from(this);

if (localSubscriptionManager.getActiveSubscriptionInfoCount() > 1) {
 //if there are two sims in dual sim mobile
    List localList = localSubscriptionManager.getActiveSubscriptionInfoList();
    SubscriptionInfo simInfo = (SubscriptionInfo) localList.get(0);
    SubscriptionInfo simInfo1 = (SubscriptionInfo) localList.get(1);

    final String sim1 = simInfo.getDisplayName().toString();
    final String sim2 = simInfo1.getDisplayName().toString();

}else{
 //if there is 1 sim in dual sim mobile
    TelephonyManager tManager = (TelephonyManager) getBaseContext()
            .getSystemService(Context.TELEPHONY_SERVICE);

    String sim1 = tManager.getNetworkOperatorName();

}

}else{
//below android API 22
        TelephonyManager tManager = (TelephonyManager) getBaseContext()
                .getSystemService(Context.TELEPHONY_SERVICE);

        String sim1 = tManager.getNetworkOperatorName();
}
相关问题