Is there anyway to update the MMS/SMS database to mark the message from read to unread and vice versa? I've tried using URI but they don't work for me.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The code below works for me to update whether a MMS message was marked as viewed or not.
To use this with SMS messages, just replace the following "content://mms/" with this "content://sms/".
/**
* Mark a single SMS/MMS message as being read or not.
*
* @param context - The current context of this Activity.
* @param messageID - The Message ID that we want to alter.
*
* @return boolean - Returns true if the message was updated successfully.
*/
public static boolean setMessageRead(Context context, long messageID, boolean isViewed){
try{
if(messageID == 0){
return false;
}
ContentValues contentValues = new ContentValues();
if(isViewed){
contentValues.put("READ", 1);
}else{
contentValues.put("READ", 0);
}
String selection = null;
String[] selectionArgs = null;
_context.getContentResolver().update(
Uri.parse("content://mms/" + messageID),
contentValues,
selection,
selectionArgs);
return true;
}catch(Exception ex){
return false;
}
}
Also, you may need to have one of the SMS permissions in your android manifest file.
Happy coding :)