How to pass a text on to the standard android messaging app?

Issue

I am developing an sms text blocking app for android. I have set up my app to be considered the default sms app, but I don’t want to have to develop the UI and systems to handle being a messaging app myself. Does anyone know a way to pass the texts to the original messaging app once I have determined I want it to go through?

For reference, here is my code for deciding whether to block an SMS:

public void onReceive(Context context, Intent intent) {
        Bundle bundle = intent.getExtras();
        Object[] pdus = (Object[]) bundle.get("pdus");
        final SmsMessage[] messages = new SmsMessage[pdus.length];
        for (int i = 0; i < pdus.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], (String)bundle.get("format"));
            long phone = PersistentData.convertNumberToLong(messages[i].getDisplayOriginatingAddress());
   if(PersistentData.contactsContains(phone)){
         if(PersistentData.contactByNumber(phone).getAllowedBy() < 1){
            // Block
         }
         else{
            // Allow
         }
      }
      else if(PersistentData.callContactsContains(phone)){
         if(PersistentData.callContactByNumber(phone).getAllowedBy() < 1){
            // Block
         }
         else{
            // Allow
         }
      }
      else{
         // Block
      }
   }
}

This receiver is set up to receive based on

<receiver android:name=".SMSReceiver"
    android:permission="android.permission.BROADCAST_SMS"
    android:exported="true">
    <intent-filter>
        <action android:name="android.provider.Telephony.SMS_DELIVER" />
    </intent-filter>
</receiver>

Solution

the way you are trying will not be possible.
Rather take any opensource sms app like telegram or chomp sms from github and add functionality you need.

Answered By – Rahul Tiwari

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published