Mark MMS as read programmatically

核能气质少年 提交于 2019-12-23 12:23:13

问题


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 :)



来源:https://stackoverflow.com/questions/6953358/mark-mms-as-read-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!