Create PDU for Android

2019-04-11 17:50发布

I am currently writing 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?

1条回答
一纸荒年 Trace。
2楼-- · 2019-04-11 18:33

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!!

查看更多
登录 后发表回答