Home > Back-end >  How to pass a text on to the standard android messaging app?
How to pass a text on to the standard android messaging app?

Time:10-21

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>

CodePudding user response:

just delete the sms programmatically if it comes from a blacklist

How to delete an SMS from the inbox in Android programmatically?

CodePudding user response:

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.

  • Related