title: Create PDU for Android that works with SmsMessage.createFromPdu() (GSM 3gpp)
body: <p><strong>Goal:</strong> (NOTE: The answer selected generates a GSM (3gpp) PDU) for <a href="https://stackoverflow.com/q/12487634/1443717">CDMA (3gpp2) please refer here</a></p>
  
  <p>To create a PDU that can be passed into <code>SmsMessage.createFromPdu(byte[] pdu)</code>.
  I'm "Broadcasting an Intent" to one of my <code>BroadcastReciever</code> that listens for SMS messages.</p>
  
  <p>One <code>BroadcastReciever</code></p>
  
  <p>Using <code>android.provider.Telephony.SMS_RECEIVED</code> for <em>"real"</em> SMS's </p>
  
  <p>Using a custom <code>intent-filter</code> action for these new <em>"application SMS's"</em>.</p>
  
  <pre><code>@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 &lt; 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());
      ...
  </code></pre>
  
  <p>So I want my <code>BroadcastReciever</code> to be able to handle both types of messages without adding extra code </p>
  
  <p>(yes I know I can have a different <code>BroadcastReciever</code> for the different <code>intent-filter</code> action but I would like to actually pull this off as I know it can be done, I'm stubborn)</p>
  
  <p><strong>Research:</strong></p>
  
  <p>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 <a href="https://stackoverflow.com/tags/pdu/hot">Stack topics on PDUs</a>, and <a href="https://stackoverflow.com/q/5822806/1443717">Create PDU Android</a> but the link is broken in the answer. I even Looked at <code>com.google.android.mms.pdu</code> source code</p>
  
  <p>so far I've only been able to create a PDU without a "<em>originating address</em>" using some code from <a href="http://www.wrankl.de/JavaPC/SMSTools.html" rel="nofollow noreferrer">http://www.wrankl.de/JavaPC/SMSTools.html</a></p>
  
  <p><strong>PDU:</strong></p>
  
  <p>destination: 555 message: helloworld</p>
  
  <pre><code>"1100038155f50000aa0ae8329bfdbebfe56c32"
  </code></pre>
  
  <p>Which obviously isn't valid...</p>
  
  <p><strong>Side Notes:</strong></p>
  
  <p>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.</p>
  
  <p>If there is anything I can add to the code I'm using to add in a <em>"originating address"</em>, that will work. Or does anyone have info on a Library I'm not aware of?</p>
  
  <p>Thanks</p>
  
  <p><strong>Updates:</strong></p>
  
  <p>tried </p>
  
  <pre><code>byte[] by =(byte[])(SmsMessage.getSubmitPdu("12345", "1234", "hello", false).encodedMessage);
  </code></pre>
  
  <p>which gives me the following (in hex representation)</p>
  
  <pre><code>"0000100200000000000000000000000004010203040000000e000320ec400107102e8cbb366f00"
  </code></pre>
  
  <p>did't work</p>