简体   繁体   English

双卡手机短信管理器?

[英]SMS Manager for Dual Sim Phones?

I am working with SMS Manager for sending sms in android.The code i am using is as below:我正在使用短信管理器在 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");
    }

}

This code works for me perfectly on single sim phones but when i check this in dual sim phones i am getting following warning and SMS never sends.这段代码在单卡手机上对我来说完美无缺,但是当我在双卡手机上检查这个时,我收到了以下警告并且短信永远不会发送。

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

Please suggest how i can achieve it on my dual sim phone.Thanks in Advance.请建议我如何在我的双卡手机上实现它。提前致谢。

This Will work for both scenario.这将适用于这两种情况。 If Already user has been selected the default sim it will automatically takes that and goto the next process, Otherwise while click on the send button it will ask the confirmation for choose any sim to send the sms.如果已经选择了默认 sim 用户,它会自动接受并进入下一个过程,否则,当点击发送按钮时,它会要求确认选择任何 sim 来发送短信。 we have tested its working fine.我们已经测试过它的工作正常。

Sample Source Code:示例源代码:

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();
}

sendTextMessage() has the scAddress parameter. sendTextMessage()具有scAddress参数。 This is used to define the SMS center address.这用于定义 SMS 中心地址。 I think if you set it correctly, you'll be able to send a message.我想如果你设置正确,你就可以发送消息。

You can find the number by following this tutorial: http://algorithmic-indian.blogspot.hu/2011/03/how-to-change-message-center-number-in.html You may try this as well how to get the smsc number of a phone in android?您可以按照本教程找到该号码: http : //algorithmic-indian.blogspot.hu/2011/03/how-to-change-message-center-number-in.html您也可以尝试此方法获取android中手机的smsc号码? Apparently there doesn't seem to be a way to programmatically get the number.显然,似乎没有办法以编程方式获取数字。

Try this code for sim selection, then use SMS sending method to send an SMS!试试这个选择sim的代码,然后使用短信发送方法发送短信!

//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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM