Intercept Incoming SMS Message and Modify it
android, cordova, iphone, sms, xamarin.ios
Solution
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.
}
}
}
}
Problem
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: - Phonegap - Mono - 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".