2011-08-05 114 views

回答

4

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

要在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权限。

快乐编码:)

相关问题