我正在使用短信管理器发送短信在android.The代码中,我使用如下:
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请提前建议如何在我的双卡phone.Thanks上实现。
发布于 2013-08-15 17:15:53
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?,显然,没有一种方法可以通过编程来获得这个数字。
发布于 2013-08-08 18:45:38
这对两种情况都有效。如果已经选择了用户,默认的SIM卡将自动进入下一个过程,否则,当点击发送按钮时,它将要求确认选择任何SIM卡来发送sms。我们已经测试了它的工作正常。
示例源代码:
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();
}发布于 2020-12-10 07:08:38
尝试使用此代码进行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();
}https://stackoverflow.com/questions/14276328
复制相似问题