Create PDU for Android
Asked Answered
A

1

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?

Alkaloid answered 28/4, 2011 at 17:41 Comment(3)
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?Frow
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.Alkaloid
@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 - https://mcmap.net/q/341524/-create-pdu-for-android-that-works-with-smsmessage-createfrompdu-gsm-3gppLoftis
G
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!!

Gesso answered 28/9, 2011 at 13:44 Comment(1)
The little green checkmark makes it automatic, yes. And thanks!Gesso

© 2022 - 2024 — McMap. All rights reserved.