Create PDU for Android

谁说我不能喝 提交于 2019-12-21 20:50:04

问题


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:


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



来源:https://stackoverflow.com/questions/5822806/create-pdu-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!