如何在Android上将所有短信标记为已读? [英] How to mark all text messages as read on Android?

查看:959
本文介绍了如何在Android上将所有短信标记为已读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户打开我的收件箱时,我试图将所有短信标记为已读.我从网上的一些教程中整理了代码,最后得到了这个:

I'm trying to mark all text messages as read when user opens my inbox. I've pieced together code from a few tutorials online and ended up with this:

 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编译代码以进行5.1的测试,并在4.4上进行测试,我的应用是默认的SMS应用.

I just want to mark all text messages as read in the onResume() function on this activity. My code may be a pile of crap, like i said it's mashed together from a few places. Corrections to, or alternatives to, my code would be very appreciated. Compiling the code with the sdk for 5.1, testing on 4.4, my app is the default SMS app.

推荐答案

如果要将所有邮件标记为已读,则可以一次性完成.

If you want to mark all messages as read, you can do that in one go.

ContentValues values = new ContentValues();
values.put(Telephony.Sms.READ, 1);
getContentResolver().update(Telephony.Sms.Inbox.CONTENT_URI, 
    values, Telephony.Sms.READ + "=0", null);

这篇关于如何在Android上将所有短信标记为已读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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