问题
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