【问题标题】:Mark MMS as read programmatically以编程方式将 MMS 标记为已读
【发布时间】:2011-08-05 08:17:21
【问题描述】:

是否有更新 MMS/SMS 数据库以将消息从已读标记为未读,反之亦然?我尝试过使用 URI,但它们对我不起作用。

【问题讨论】:

    标签: android mms


    【解决方案1】:

    下面的代码可以让我更新彩信是否被标记为已查看。

    要将其用于 SMS 消息,只需将以下“content://mms/”替换为“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;
        }
    }
    

    此外,您可能需要在您的 android 清单文件中拥有 SMS 权限之一。

    编码愉快:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-18
      • 2016-03-05
      • 1970-01-01
      相关资源
      最近更新 更多