3
我嘗試做的是發送短信到另一部手機,並得到確認,如果短信發送與否。 現在,只有確認短信已發送的作品。所以我得到的消息是,我的短信已發送,但我什麼都沒有收到。 我使用2個模擬器來測試它,但我不認爲這是問題。偏偏我沒有手機用andoid一個瞬間:(安卓:未收到SMS發送的確認在模擬器
我的代碼如下所示:
private void sendSms(String txt, String phone){
PendingIntent sentPI = PendingIntent.getBroadcast(act, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(act, 0, new Intent(DELIVERED), 0);
//---when the SMS has been sent---
act.registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(act, "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(act, "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(act, "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(act, "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(act, "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
act.registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(act, "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(act, "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phone, null, txt, sentPI, deliveredPI);
}
多麼可憐buzinga! – ruben 2013-09-19 12:46:11
這個鏈接是死 – joao2fast4u 2015-12-30 11:43:46
這就是爲什麼我引用的文章的相關部分,@ joao2fast4u – msal 2015-12-31 02:20:06