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