Mark MMS as read programmatically
Asked Answered
V

1

4

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.

Vivacious answered 5/8, 2011 at 8:17 Comment(0)
I
4

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

Indelicate answered 27/10, 2011 at 16:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.