android – SMS Manager for Dual Sim Phones?-ThrowExceptions

Exception or error:

I am working with SMS Manager for sending sms in android.The code i am using is as below:

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.

How to solve:

sendTextMessage() has the scAddress parameter. This is used to define the SMS center address. 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? Apparently there doesn’t seem to be a way to programmatically get the number.

###

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

Leave a Reply

Your email address will not be published. Required fields are marked *