title: Android - Modify SMS Body before arriving the Inbox
body: <p>Currently I am trying to modify an incoming SMS before it is saved to the Inbox.
  As the system is Android 4.4.4, a simple interception with a high priority broadcast receiver is not possible. That is also the reason why I'm modifying the Android Source (AOSP) and not building an App.</p>
  
  <p>So far I have managed to identify a promising class: InboundSmsHandler. Within the inner class SmsBroadcastReceiver the method onReceive is triggered when a SMS has arrived and later on sends an "SMS_RECEIVED" intend. So basically this method seems to be at a good spot.</p>
  
  <p>The problem is that I can not modify the SMS that is delivered with the intend of onReceive.
  <em>I have already tried to modify it with PDU:</em></p>
  
  <pre><code>byte[] pdu = createFakePDU("15555215556", "modified body");
  intent.putExtra("pdus", new Object[] { pdu });
  intent.putExtra("format", "3gpp");
  </code></pre>
  
  <p>(This approach did not work, the SMS App has shown the original message)</p>
  
  <p><em>Tried to modify the body of a SmsMessage directly:</em>
  (I have added a method to SmsMessage to be able to modify the body)</p>
  
  <pre><code>SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
  int pduCount = msgs.length;
  for(int i=0; i&lt;pduCount; i++)
  {
      msgs[i].modifyBody("test");
  }
  </code></pre>
  
  <p>(This approach did not work, the SMS App has shown the original message)</p>
  
  <p><em>And finally added a new SMS to the database:</em></p>
  
  <pre><code>....
  contentResolver.insert( Uri.parse( SMS_URI ), values );
  
  ....
  </code></pre>
  
  <p>(The problem with that approach is that the original SMS still arrives and therefore not only one modified SMS but one original SMS and one modified arrive. The original SMS must be deleted, but I don't know how.)</p>
  
  <p>Does anyone know how I can modify a SMS before it arrives at the Inbox?</p>
  
  <p>Best regards
  mint</p>