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.
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();
}
Try this code for sim selection, then use SMS sending method to send an 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();
}