[Android] Text Message application-real-time deletion of text messages (sessions)

Source: Internet
Author: User

In my previous articles, I wrote examples of real-time text message retrieval and text message (Session) deletion.

Related links:

SMS information Real-time acquisition: http://blog.csdn.net/etzmico/article/details/6860692

SMS (Session) Deletion: http://blog.csdn.net/etzmico/article/details/7077123

Therefore, the code for the above two methods will not be written in this article. You can click the link to view the code.

This time they are combined, but some small details need to be noted,

First, declare contentresolver in the activity class and define it in oncreate.

static ContentResolver cr;cr = getContentResolver();

Secondly, in the short message receiving mechanism of Android, the system first listens to the message, then stores the message in the inbox, and prompts in the notification. The system does not immediately store the message in the inbox and prompt after listening to the text message, therefore, pay special attention to the deletion.

New timer (). Schedule (New timertask () {@ overridepublic void run () {// Delete SMS code}, 5000 );

We can make such an extension because there is no information in the inbox when the onreceive method in the text message receiving trigger class is received, even if the priority is minimized, it will not help.
Therefore, we can perform a delay operation on the method for deleting text messages. According to my own test, five seconds is wonderful, because many machines will become slow in system operation for various reasons ...... If the machine gets stuck again, you can add more events ...... Here, 5000 is 5000 milliseconds, that is, 5 seconds.

In addition, to avoid text message deletion, we can determine if and add conditions for the method.

Stringbuffer smsaddress. append (message. getdisplayoriginatingaddress (); // the sender's phone number stringbuffer smscontent. append (message. getdisplaymessagebody (); // SMS content

In this way, the text message will not be deleted by mistake.

At last, the system prompts three permissions in manifest. xml.

    <uses-permission android:name="android.permission.RECEIVE_SMS" />    <uses-permission android:name="android.permission.WRITE_SMS" />    <uses-permission android:name="android.permission.READ_SMS" />

Demo download: http://download.csdn.net/detail/etzmico/3975608

Related Article

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.