Android 短信发送失败通知 : false positive

标签 android sms smsmanager

我的应用程序从一台设备向另一台设备发送短信。

问题是当接收设备关闭时,我仍然收到 OK 通知 Intent 。

这是当 SMS 真正发送(第一行)时以及由于第二台设备关闭而未发送时我得到的结果:

delivered: intent=Intent { act=SMS_DELIVERED flg=0x10 (has extras) } extras=Bundle{ pdu => [B@41a7a850; format => 3gpp; }Bundle
delivered: intent=Intent { act=SMS_DELIVERED flg=0x10 (has extras) } extras=Bundle{ pdu => [B@41719ae8; format => 3gpp; }Bundle

是否有一种可移植(不依赖于提供商)的方法来查明 SMS 是否已发送?

最佳答案

函数SmsMessage.getStatus()给出一个状态码。状态码 0 表示成功(好吧,仅适用于 GSM);非零状态码取决于它是 CDMA 还是 GSM 消息。

因此:

int status = -1;
byte[] pdu = intent.getByteArrayExtra("pdu");
if (pdu != null) {
    SmsMessage sms = SmsMessage.createFromPdu(pdu);
    status =  sms.getStatus();
}

相应地,当接收设备关闭和打开时,我进入日志:

status = 0x30
status = 0x0

但这还不是全部:C.S0015-B, v2.0, 4.5.21 ( link )(对于 CDMA)读取(注意 Android 将这些值左移 16 位,并且将状态字节分成两个执行 status = mBearerData.errorClass << 8; status |= mBearerData.messageStatus; ):

Status
Code     Message Status 
ERROR_CLASS = ‘00’ (no error) 
‘000000’ Message accepted 
‘000001’ Message deposited to Internet 
‘000010’ Message delivered 
‘000011’ Message cancelled 

ERROR_CLASS = ‘10’ (temporary condition) 
‘000100’ Network congestion 
‘000101’ Network error 
‘011111’ Unknown error 

ERROR_CLASS = ‘11’ (permanent condition) 
‘000100’ Network congestion 
‘000101’ Network error 
‘000110’ Cancel failed 
‘000111’ Blocked destination 
‘001000’ Text too long 
‘001001’ Duplicate message 
‘001010’ Invalid destination 
‘001101’ Message expired 
‘011111’ Unknown error 
All other values reserved. 

TS 23.040, 9.2.3.15 TP-Status ( link )(对于 GSM)如下:

Short message transaction completed
0000000 Short message received by the SME
0000001 Short message forwarded by the SC to the SME but the SC is
unable to confirm delivery
0000010 Short message replaced by the SC
Reserved values
0000011..0001111 Reserved
0010000..0011111 Values specific to each SC

Temporary error, SC still trying to transfer SM
0100000 Congestion
0100001 SME busy
0100010 No response from SME
0100011 Service rejected
0100100 Quality of service not available
0100101 Error in SME
0100110..0101111 Reserved
0110000..0111111 Values specific to each SC

Permanent error, SC is not making any more transfer attempts
1000000 Remote procedure error
1000001 Incompatible destination
1000010 Connection rejected by SME
1000011 Not obtainable
1000100 Quality of service not available
1000101 No interworking available
1000110 SM Validity Period Expired
1000111 SM Deleted by originating SME
1001000 SM Deleted by SC Administration
1001001 SM does not exist (The SM may have previously existed in the SC but the SC
        no longer has knowledge of it or the SM
        may never have previously existed in the SC)
1001010..1001111 Reserved
1010000..1011111 Values specific to each SC

Temporary error, SC is not making any more transfer attempts
1100000 Congestion
1100001 SME busy
1100010 No response from SME
1100011 Service rejected
1100100 Quality of service not available
1100101 Error in SME
1100110..1101001 Reserved
1101010..1101111 Reserved
1110000..1111111 Values specific to each SC

只检查 0 是不正确的,因为状态代码可能恰好是 2,而事实上,CDMA“消息传递”代码是 2 而不是 0! 重要的是要知道是否会进行更多尝试,即检查位 5-6 或 4-5(甚至消息类别位组合具有不同的含义!)值 0x30在我上面的日志中表示 0110000 “特定于服务中心的值”和0x0表示“SME 收到的短消息”,其中 SME(短消息实体)是任何支持 SMS 的事物,即本例中的接收设备。

现在,您必须intent.getStringExtra("format")并取决于它是否是 "3gpp""3gpp2"解码状态码。

如果有人可以编写代码在GSM和CDMA网络下测试它,请发布测试代码!

关于Android 短信发送失败通知 : false positive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33174463/

相关文章:

java - SmsManager 在发送每条短信之间有延迟

android - 从未传递消息的 SMS 内容 URI 中获取消息

Android-使用剪贴板从 TextView 复制和粘贴所需字符串的代码

android - 在 list 文件中找不到 MainActivity,但我声明了它

android - 设置Android Studio但如何?

java - smslib 不发送短信为什么?

java - 如何在 Android 中发送短信?

android - 如何将 fragment 添加到 ViewPager? addView 使我的应用程序崩溃

calendar - 当我的日历有繁忙事件时,如何以编程方式将来电重定向到语音邮件

python - 如何向python脚本发送短信?