Skip to content Skip to sidebar Skip to footer

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 using URI but they don't work for me.

Solution 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.
 */publicstaticbooleansetMessageRead(Context context, long messageID, boolean isViewed){
    try{
        if(messageID == 0){
            returnfalse;
        }
        ContentValuescontentValues=newContentValues();
        if(isViewed){
            contentValues.put("READ", 1);
        }else{
            contentValues.put("READ", 0);
        }
        Stringselection=null;
        String[] selectionArgs = null;          
        _context.getContentResolver().update(
                Uri.parse("content://mms/" + messageID), 
                contentValues, 
                selection, 
                selectionArgs);
        returntrue;
    }catch(Exception ex){
        returnfalse;
    }
}

Also, you may need to have one of the SMS permissions in your android manifest file.

Happy coding :)

Post a Comment for "Mark Mms As Read Programmatically"