Android短信发送失败通知:误报

时间:2015-10-16 15:40:57

标签: android sms smsmanager

我的应用程序将SMS从一个设备发送到另一个设备。

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

这是我真正交付短信(第1行)时所得到的,以及由于第二台设备关闭而未送达的时间:

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是否已经交付?

1 个答案:

答案 0 :(得分:1)

函数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&#34;消息已经传送到#34;代码是2而不是0! 重要的是知道是否会进行更多尝试,即检查5-6或4-5位(甚至消息类位组合具有不同的含义!)我的日志中的值0x30以上是指0110000&#34;特定于服务中心的价值&#34; 0x0表示&#34;中小企业收到的短信&#34;其中SME(短消息实体)是任何支持SMS的东西,也就是这种情况下的接收设备。

现在,您必须intent.getStringExtra("format"),具体取决于"3gpp""3gpp2"解码状态代码。

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