Android Development Delete SMS

Source: Internet
Author: User

I have always had a demand, want mobile phone automatically block the blacklist of contact information and automatically delete these text messages, mobile phone butler and other software can intercept but did not find can delete these messages, and then began to want to write an Android software idea.

With the rise of the Internet of things, the development of Android devices is sure to have a good future. Then learned that Android development can be used in the Java language, with Eclipse, hehe, I still have some Java foundation, so, I began to thump.

After setting up the Eclipse SDK ADT, I started to develop this software that automatically intercepts and removes the blacklist text messages. have been implemented.

In the process of writing, delete the text message module is the pit I quite long time, because the function call when the parameter value is not written well, the version of the Web more, at that time crt+v pit I long, now the deletion of SMS module sent. I tried it on my phone, and I tested it available.

 Public voiddeletesms (String smscontent) {Try        {            //Prepare the system text message to receive the URI address of the mailboxUri uri = uri.parse ("Content://sms/inbox");//Collect mail//Check all the messages in the Inbox .string[] Projection =NewString[] {"_id", "address", "person", "body", "date", "type", "thread_id"};//"_id", "address", "person", "date", "Type "String where = "address = ' 10001 '"; Cursor Curs= Getcontentresolver (). Query (URI, projection, where,NULL, "Date desc"); if(Curs.movetofirst ()) { Do{                    //String phone =//isread.getstring (Isread.getcolumnindex ("Address")). Trim ();//Get SenderString Body =curs.getstring (Curs.getcolumnindex ("Body")). Trim ();//Get information Content                    if(Body.contains (smscontent)) {intid = curs.getint (curs.getcolumnindex ("_id")); Getcontentresolver (). Delete (Uri.parse ("content://sms/"), "_id=?",Newstring[]{string.valueof (ID)}); }                } while(Curs.movetonext ());        } curs.close (); }        Catch(Exception e) {e.printstacktrace (); }    }

The idea of the algorithm is: the sender is 10001 of all text messages, containing a string of text messages to delete, want to change the contents of the text message to another _id, such as the sender of the modified function can be AH.

The function of calling this module is implemented with a button onclicklistener.

        Btndelmsg.setonclicklistener (new  Onclicklistener ()        {            @Override            public void OnClick (View v)            {                //  TODO auto-generated method stub                deletesms ("Dear Customer, intercept");}        );

A relatively clear and concise reference link

http://wx1985113.iteye.com/blog/1231094

Summarize:

3 Ways to delete SMS function parameters

Getcontentresolver (). Delete (Uri.parse ("content://sms/"), "_id=?", New string[]{string.valueof (ID)});
Getcontentresolver (). Delete (Uri.parse ("content://sms/"), "_id=" +id,null);
Getcontentresolver (). Delete (Uri.parse ("content://sms/" +id), null,null);

Android Development Delete SMS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.