[英]SMS Manager for Dual Sim Phones?
我正在使用短信管理器在 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
请建议我如何在我的双卡手机上实现它。提前致谢。
这将适用于这两种情况。 如果已经选择了默认 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();
}
sendTextMessage()
具有scAddress
参数。 这用于定义 SMS 中心地址。 我想如果你设置正确,你就可以发送消息。
您可以按照本教程找到该号码: http : //algorithmic-indian.blogspot.hu/2011/03/how-to-change-message-center-number-in.html您也可以尝试此方法获取android中手机的smsc号码? 显然,似乎没有办法以编程方式获取数字。
试试这个选择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.