0
我試圖在用戶打開收件箱時將所有短信標記爲已讀。我從一些在線教程拼湊起來的代碼,並結束了與此:如何在Android上將所有短信標記爲已讀?
Uri uri = Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(uri, null, null, null, null);
while (cursor.moveToNext()) {
if ((cursor.getInt(cursor.getColumnIndex("read")) == 0)) {
String SmsMessageId = cursor.getString(cursor.getColumnIndex("_id"));
ContentValues values = new ContentValues();
values.put("read", true);
getContentResolver().update(Uri.parse("content://sms/inbox"), values, "read=0", null);
}
我只想標記爲在這次活動的onResume()函數讀取所有短信。我的代碼可能是一堆垃圾,就像我說的,它是從幾個地方一起搗碎的。更正或替代我的代碼將非常感激。使用sdk for 5.1編譯代碼,在4.4上測試,我的應用程序是默認的SMS應用程序。
@DoğanKılıç什麼是默認的應用程序與查詢更新消息讀取狀態呢?這是從KK開始對所有數據庫進行修改的先決條件,並非特定於此查詢。 – fejd