Compared with those who have used Android phones, we all know that androidos text messages are displayed in session mode like those in iOS, which makes it easy for users to find previous chat records.
UsageCodeDeleting a text message actually deletes a conversation, both recent and previous.
Next let's look at the code.
First, you need to get the text message directory.
Contentresolver CR; CR = getcontentresolver ();
Then, you need to review all text messages.
String sms_read_column = "read"; string where_condition = sms_read_column + "= 0"; string sort_order = "date DESC"; int COUNT = 0; cursor = CR. query (URI. parse ("content: // SMS/inbox"), new string [] {"_ id", "thread_id", "Address", "person", "date ", "body"}, where_condition, null, sort_order); If (cursor! = NULL) {try {COUNT = cursor. getcount (); If (count> 0) {cursor. movetofirst (); threadid = cursor. getlong (1) ;}} finally {cursor. close ();}}
"Content: // SMS/inbox" is the path of the SMS, inbox, and inbox.
The above code can get the latest text message.
We need to call this method. We can call this method.
Long id = getthreadid (); Uri muri = URI. parse ("content: // SMS/conversations/" + id );
In this way, you can get the ID of the latest hop SMS.
Delete the file.
Cr. Delete (muri, null, null );
Do not forget to add permissions to manifest. xml.
<Uses-Permission Android: Name = "android. Permission. write_sms"/> <uses-Permission Android: Name = "android. Permission. read_sms"/>
In addition, if you want to obtain the latest inbox information, you must obtain the ID again. The ID here is always 0, but if you directly replace the ID with 0, the deleted items are not the latest ones.
If you want to delete other text messages, you only need to add conditions during traversal so that the returned ID is the session ID corresponding to the condition,
Another point is to emphasize that this method can only delete unread text message conversations, because its search condition is inbox, which is of course the inbox; if the text message is read, then the Android system should determine that the information is not in the inbox.
Demo download: http://download.csdn.net/detail/etzmico/3975576