0

I want to read all incoming SMS text messages once they arrive and delete those that contain a particular keyword. How can I do this?

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
xyzandroid
  • 139
  • 1
  • 3
  • 9

1 Answers1

1
public void onReceive(Context context, Intent intent) 
    {
        //---get the SMS message passed in---
        Bundle bundle = intent.getExtras();        
        SmsMessage[] msgs = null;
        String msgString = "",senderinfo = ""; 


        if (bundle != null)
        {
            //---retrieve the SMS message received---
            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]);                
                senderinfo += msgs[i].getOriginatingAddress();


                msgString += msgs[i].getMessageBody().toString();

            }
            //---display the new SMS message---
            Toast.makeText(context, senderinfo, Toast.LENGTH_SHORT).show();
        }
if(msgString.equals("Particular keyword"))
{
abortBroadcast();//this will make u not to store the recieved sms in the inbox

}
user1203673
  • 1,015
  • 7
  • 15