开发者

Create PDU for Android

I am currently writi开发者_Python百科ng and application, that is sending/receiving SMS messages.

For unit-testing purposes I need to create PDU programmatically. Decoding is quite easy:

Bundle bundle = intent.getExtras();
if (bundle != null) {
    /* Get all messages contained in the Intent*/
    Object[] pdusObj = (Object[]) bundle.get("pdus");
    for (int i = 0; i < pdusObj.length; i++) {
        SmsMessage msg = SmsMessage.createFromPdu((byte[])pdusObj[i]);
    }
}

Is there any appropriate way to create PDU programamtically?


Typically PDUs are hardcoded in the code. Similar to this:

String pdu = "07914151551512f2040B916105551511f100006060605130308A04D4F29C0E";
SmsMessage sms = SmsMessage.createFromPdu(HexDump.hexStringToByteArray(pdu));

Here's a complete example on how to do this.

Now, you're gonna ask me "where can I find a PDU for testing?" You generate it. For example, you can use this online service.

I hope this helps!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜