马克彩信为已读编程 [英] Mark MMS as read programmatically

查看:162
本文介绍了马克彩信为已读编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正有没有更新MMS / SMS数据库从读未读,反之亦然,以将邮件标记?我已经使用URI尝试,但他们不为我工作。

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.

推荐答案

以下作品中的code对我来说,更新MMS消息是否被标记为观看与否。

The code below works for me to update whether a MMS message was marked as viewed or not.

要使用与短信,只需更换以下的内容:// MMS /与此有关。内容://短信/

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;
    }
}

另外,你可能需要在你的Andr​​oid清单文件中的短信权限之一。

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

编码快乐:)

这篇关于马克彩信为已读编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆