我有一个java卡小程序,可以接收二进制短信并处理它们。现在我需要检查它们是否来自特定的短号码。
这就是我所做的
case EVENT_FORMATTED_SMS_PP_ENV:{
final EnvelopeHandler eh = EnvelopeHandler.getTheHandler();
short sd_len = eh.getSecuredDataLength();
short sd_offset = eh.getSecuredDataOffset();
byte[] tmpData = new byte[10];
short dataLen = 0;
if (eh.findTLV(ToolkitConstants.TAG_ADDRESS, (byte) 1) != ToolkitConstants.TLV_NOT_FOUND) {
dataLen = eh.getValueLength();
eh.copyValue((short)0,tmpData,(short)0,(short)dataLen);
}
actions.showNumberBuffer(tmpData, (short)dataLen);
break;
}
我成功收到地址,但它与发送二进制短信的短号码不同 也许有其他方法可以得到短号码?
最佳答案
地址TLV是服务中心地址。
发送者的地址是 SMS-TPDU TLV 内的 TP-OA。 因此,您需要手动解析它。
这是一个例子:
// Format of data under first SMS TPDU TLV, taken using EnvelopeHandler.findTLV()
// ----------+-----+---------+---------+--------+--------+---------+--------+-------+
// 1 | 1 | 1 | 0~10 | 1 | 1 | 7 | 1 | 0~140 |
// ----------+-----+---------+---------+--------+--------+---------+--------+-------+
// | Len | TON/NPI | Address | | | | | |
// TP-MTI... | TP-OA | TP-PID | TP-DCS | TP-SCTS | TP-UDL | TP-UD |
// ----------+-----+---------+---------+--------+--------+---------+--------+-------+
// Get received TPOA
EnvelopeHandler envHdlr = EnvelopeHandler.getTheHandler();
envHdlr.findTLV(ToolkitConstants.TAG_SMS_TPDU, (byte) 1);
// Assign TPOA to a buffer [0] for bytes-length [1..12] for the value as coded in 3GPP TS 23.040
envHdlr.copyValue((short) 1, tpdaBuf, (short) 1, (short) 12);
byte lengthTPOA = (byte) ((tpdaBuf[1] + 5) / 2);
tpdaBuf[0] = lengthTPOA;
关于java - 小程序中收到二进制格式的短信如何获取短号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20235953/