如何在Android上删除包含特定关键字的文字?

时间:2012-02-15 05:35:43

标签: android sms

我想在收到所有收到的短信后阅读这些短信,并删除包含特定关键字的短信。我怎么能这样做?

2 个答案:

答案 0 :(得分: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

}

答案 1 :(得分:0)

看:Delete SMS in Android 1.5这对你有用。

您是否也想阅读收件箱?或只是收到消息?