Jav*_*ere 3 sms android confirmation
我尝试做的是将短信发送到另一部手机,并在短信被送达时获得确认.现在,只确认已发送短信有效.所以我收到消息说我的短信已被发送,但后来我什么都没得到.我正在使用2个模拟器来测试它,但我不认为这是问题所在.不幸的是,我没有手机与andoid片刻:(
我的代码看起来像这样:
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);
}
Run Code Online (Sandbox Code Playgroud)
根据mobiforge.com上的"Android中的SMS消息"教程,交付状态报告不适用于模拟器:
成功交付后,将显示"已发送短信"消息.请注意,对于使用模拟器进行测试,当成功传送SMS时,不会出现"SMS传送"消息; 这仅适用于真实设备.
| 归档时间: |
|
| 查看次数: |
2264 次 |
| 最近记录: |