breezing
breezing

Reputation: 1

How to update android sms conversation thread?

I wanted to update the "message_count" column and "snippet" column of a sms conversation thread, using this content:"content://mms-sms/conversations". Because the snippet and message count is not updated when an SMS is deleted from the conversation thread. But I got this error message: "MmsSmsProvider does not support deletes, inserts, or updates for this URI" Below is my code:

ContentValues values = new ContentValues();
values.put("message_count", ent.getValue().getCount());
values.put("snippet", ent.getValue().getSnip());

Uri conUri = Uri.parse("content://mms-sms/conversations");
getContentResolver().update(conUri, values, null, null);

I also try like this:

Uri conUri = Uri.parse("content://mms-sms/conversations" + "/" + threadid);
getContentResolver().update(conUri, values, null, null);

But what I got is another error message:no such column: message_count: , while compiling: UPDATE pdu SET message_count=?,snippet=? WHERE thread_id=334

Thanks for any help

Upvotes: 0

Views: 4902

Answers (1)

Pinal
Pinal

Reputation: 41

There is no way to update the count, snippet etc of a thread directly. But I can help you with your actual problem. There is actually a bug in the android code, which is the root of your issue. When you try to delete in the following way -

getContentResolver().delete("content://sms/", "_id=?", new String[] {id});

Android does not update the thread associated with that sms.

The solution is is to do this

getContentResolver().delete("content://sms/" + id, null, null);

For those who are curious what the bug is - Android code does something stupid like this, when you delete using method 1 -

  1. Delete all messages given by the query.
  2. Get all the conversation threads associated with the messages given by the query and update them. Whoa wat ?! Step 1 just deleted messages given by query so, step 2 is always going to return a null set for threads associated with those message, as all the messages are already deleted.

Hope this helps.

Upvotes: 4

Related Questions