开发者

Mark MMS as read programmatically

Is there anyway to update the MMS/SMS database to mark the message from read to unread and vice versa? I've tried u开发者_运维技巧sing URI but they don't work for me.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜