0

Possible Duplicate:
Can we delete an SMS in Android before it reaches the inbox?

I've already gotten receive SMS code running successfully. What I cannot determine is a way (or if it's possible) to process messages sent from specific phone numbers within my app without them being made visible to the user. All other SMS's sent from other phone number would be handled by the normal Android SMS processing. I.e., SMS's from selected numbers should not be visible to the phone user and the rest should. Any suggestions?

Here's the SMSReceiver code (taken straight from Wei-Meng Lee's book):

public class SMSReceiver extends BroadcastReceiver {
    @Override
        public void onReceive(Context context, Intent intent) {
            //get the received SMS message
        Bundle bundle = intent.getExtras();
            SmsMessage[] msgs = null;
            String str = "";
            if (bundle != null) {
                // retrieve the SMS message 
                Object[] pdus = (Object[]) bundle.get("pdus");
                msgs = new SmsMessage[pdus.length];
                for (int i=0; i<msgs.length; i++) {
                    msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
                    str += "SMS from " + msgs[i].getOriginatingAddress();
                    str += "\nMessage Text:\n";
                    str += msgs[i].getMessageBody().toString();
                    str += "\nLength="+msgs[i].getMessageBody().toString().length()+"\n";
                }  // [END FOR]
            // display the new SMS message
            Toast.makeText(context, str, Toast.LENGTH_SHORT).show();            
            // send a broadcast intent to update the SMS received in the activity
            Intent broadcastIntent = new Intent();
            broadcastIntent.setAction("SMS_RECEIVED_ACTION");
            broadcastIntent.putExtra("sms", str);
            context.sendBroadcast(broadcastIntent);
        }  // [END IF]
    }  // [END onReceive]
}  // [END SMSReceiver]
Community
  • 1
  • 1
PeteH
  • 1,870
  • 25
  • 23

1 Answers1

1

well if you put an if before you start concatenating str, you can check the originating address, and compare it to your blacklist of addresses, if its on the list, then simply use the continue to skip the concatenations

dannyRods
  • 552
  • 6
  • 23
  • 1
    This is part of the answer. The full solution requires searching for the whitelisted (or blacklisted) numbers and then using abortBroadcast() to stop propogation of SMS's you *do not* want Android to process as normal text messages. – PeteH Jan 18 '13 at 20:21