3

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?

maxk
  • 642
  • 1
  • 9
  • 21
  • I'm not clear why you are unit testing the PDU since that is handled by Android. Don't you really want to just test you logic and not googles? – Jim Apr 28 '11 at 18:36
  • 1
    It is not a matter of whose logic is it. I am testing my application works correctly even if the environment (Mobile Service Provider or device) is not. Currently, I am testing using the straight-forward approach and I would like to start a broadcast 'android.provider.Telephony.SMS_RECEIVED' with Intent and proper bundles attached to test my code works correctly. – maxk Apr 29 '11 at 15:01
  • @ibo.ezhe Did you ever successfuly Create a PDU programtically that could be decoded with the createFromPDU() method? I've been dancing around this problem for a week. I have the same question with 50 bounty on it - http://stackoverflow.com/q/12335642/ – StrikeForceZero Sep 15 '12 at 10:04

1 Answers1

11

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

Emmanuel
  • 16,791
  • 6
  • 48
  • 74