Reputation: 121
I have tried to use the undocumented content provider (content://sms) to insert a SMS into the inbox, and the insertion is successful. Then I check the newly inserted mesage in the Messaging apps, however the time displayed is always the real time that the insertion is done, instead of the time I specified in ContentValues. After I clicked and viewed the message thread, the time is then updated to the value I set in ContentValues. Have I missed something? Please help, thanks so much
Her is part of my code
Uri uri = Uri.parse("content://sms");
ContentValues cv = new ContentValues();
cv.put("address", "99912345");
cv.put("date", 1309632433677);
cv.put("read", 1);
cv.put("type", 1);
cv.put("subject", null);
cv.put("body", "Testing message");
getContentResolver().insert(uri, cv);
Upvotes: 4
Views: 4099
Reputation: 189
Exactly this one worked for me:
getContentResolver().delete(Uri.parse("content://sms/conversations/-1"), null, null);
Upvotes: 8
Reputation: 2814
Even faster, just delete the -1th
conversation (which doesn't exist) from sms/conversations
uri to trigger the trigger.
contentResolver.delete(Uri.parse('content://sms/conversations/-1'), null, null);
Upvotes: 5
Reputation: 1663
The problem is that this is an undocumented, unofficial API, so in theory, you maybe shouldn't be using it. In practice, if you want to use it, you have to be prepared for Google to break your software in the J or some later release.
All that said, it turns out that there's a workaround. When you insert a message, that sets the thread's datestamp to the time of insert. But when you delete a message from a thread (identified by the "address" field in the "content://sms" provider), it has to recalculate the thread datestamp. So for every thread you stuff something into, stuff another dummy message in as well and then delete it. Which is easy because the insert method returns a Uri that you can call the delete method on. I suspect this is horribly inefficient.
Upvotes: 11
Reputation: 6592
On many phones this cannot be avoided as the messaging application is displaying the date time from the threads table which date time is build from an insert trigger. Some phones will allow you to update the threads provider but this will not work on all platforms.
Upvotes: 0