[英]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.