Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intercept Incoming SMS Message and Modify it

Is there a way to intercept an incoming SMS message, and then modify it before presenting it to the user?

  • Can it be done natively on iPhone / Andriod?
  • Can it be done using PhoneGap?
  • Can it be done using MonoTouch / Mono for Andriod?

If yes to any of the above, could you please provide some pointers to it?

My preferred-solution priority-order is as follows:

  1. Phonegap
  2. Mono
  3. Native

Thank you all in advance!!

EDIT:

For people wondering what is the purpose of this, basically I would like to put a word as a "label" in the sms depending on the content, so when I view the sms, I can see something like "IMPORTANT: blah blah blah", instead of just "blah blah blah".

like image 827
user2243110 Avatar asked Apr 09 '13 05:04

user2243110


2 Answers

try out this- //register this class as receiver in manifest file for SMS_RECEIVED intent

  public class SmsReceiver extends BroadcastReceiver {

    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(SMS_RECEIVED)) {
              abortBroadcast();**this is prevent message to deliver to user**

            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                // get sms objects
                Object[] pdus = (Object[]) bundle.get("pdus");
                if (pdus.length == 0) {
                    return;
                }
                // large message might be broken into many
                SmsMessage[] messages = new SmsMessage[pdus.length];
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < pdus.length; i++) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    sb.append(messages[i].getMessageBody());
                }
                String sender = messages[0].getOriginatingAddress();
                String message = sb.toString();
                Toast.makeText(context, message, Toast.LENGTH_SHORT).show();

               SmsManager sms = SmsManager.getDefault();
               sms.sendTextMessage(phoneNumber, null, message, null, null);//phone number will be your number. 
            }
        }
    }
}
like image 98
Sharad Mhaske Avatar answered Sep 23 '22 20:09

Sharad Mhaske


Sure! The EASIEST way on iOS is just to create a trigger on the SMS database - /var/mobile/Library/SMS/sms.db

CREATE TRIGGER AFTER INSERT ON message 

then update the record!

The more advanced way of doing it, is hooking private methods, but I won't go that deep right now, you just need to explore the methods :)

BTW, you in any way you NEED a jailbroken device

like image 21
Dimitar Marinov Avatar answered Sep 22 '22 20:09

Dimitar Marinov