Goal: (NOTE: The answer selected generates a GSM (3gpp) PDU) for CDMA (3gpp2) please refer here
To create a PDU that can be passed into SmsMessage.createFromPdu(byte[] pdu)
.
I'm "Broadcasting an Intent" to one of my BroadcastReciever
that listens for SMS messages.
One BroadcastReciever
Using android.provider.Telephony.SMS_RECEIVED
for "real" SMS's
Using a custom intent-filter
action for these new "application SMS's".
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
// getting SMS information from Pdu.
for (int i = 0; i < pdusObj.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
}
for (SmsMessage currentMessage : messages) {
//the currentMessage.getDisplayOriginatingAddress()
//or .getDisplayMessageBody() is null if I Broadcast a fake sms
Log.i("BB", "address:"+currentMessage.getDisplayOriginatingAddress()+" message:"+currentMessage.getDisplayMessageBody());
...
So I want my BroadcastReciever
to be able to handle both types of messages without adding extra code
(yes I know I can have a different BroadcastReciever
for the different intent-filter
action but I would like to actually pull this off as I know it can be done, I'm stubborn)
Research:
I've been doing research all day/night. I've tried writing my own even though I'm very terrible with the math and conversions and creating a suitable algorithm. I've looked over Stack topics on PDUs, and Create PDU Android but the link is broken in the answer. I even Looked at com.google.android.mms.pdu
source code
so far I've only been able to create a PDU without a "originating address" using some code from http://www.wrankl.de/JavaPC/SMSTools.html
PDU:
destination: 555 message: helloworld
"1100038155f50000aa0ae8329bfdbebfe56c32"
Which obviously isn't valid...
Side Notes:
I don't plan on doing anything with the PDU besides local use, I do not want hard coded PDU's in my code because I'm not reusing the PDU.
If there is anything I can add to the code I'm using to add in a "originating address", that will work. Or does anyone have info on a Library I'm not aware of?
Thanks
Updates:
tried
byte[] by =(byte[])(SmsMessage.getSubmitPdu("12345", "1234", "hello", false).encodedMessage);
which gives me the following (in hex representation)
"0000100200000000000000000000000004010203040000000e000320ec400107102e8cbb366f00"
did't work
broadcast receiver
can catch, i will add an answer – Artfulbyte[]
as if it was a "real" SMS that was sent to that device.SmsMessage.createFromPdu()
needs to be able to parse it properly. so yes if you have code that can "create like real sms which built-in broadcast receiver can catch" that would be perfect. – GeigerSmsMessage.createFromPdu()
– Geiger