Android:标记文本消息 (SMS) 未读

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11100031/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 06:00:15  来源:igfitidea点击:

Android: Marking text message (SMS) unread

androidsms

提问by pinkfloydhomer

For some reason, NO sms app on android seem to offer the very basic feature (that even old dumb-phones have) of marking an SMS unread.

出于某种原因,Android 上没有短信应用程序似乎提供了标记短信未读的非常基本的功能(即使是旧的傻瓜手机也有)。

I am considerinng writing such an app myself, but before I begin I would like to know a little bit about how to do it and why it hasn't been done before. Surely it is not impossible?

我正在考虑自己编写这样的应用程序,但在开始之前,我想了解一下如何去做以及为什么以前没有这样做过。当然不是不可能吗?

采纳答案by abhy

NOTE:Firstly, just to let you know in Android it is little typical to work with Messaging Systemin Android(2.3 or lower) as to work with things like SMS requires to query with Content Providers which is officially not available and also Android guys have warned about it. You can check about it in the below URL: http://android-developers.blogspot.in/2010/05/be-careful-with-content-providers.html

注意:首先,只是为了让您知道在 Android 中使用消息系统在 Android(2.3 或更低版本)中很少典型,因为处理 SMS 之类的事情需要使用官方不可用的内容提供程序进行查询,而且 Android 人员也有对此发出警告。您可以在以下 URL 中查看:http: //android-developers.blogspot.in/2010/05/be-careful-with-content-providers.html

Further for your solution and just for everybody's concern would like to divide my explanation according to Android OS versions:

进一步为您的解决方案,只是为了大家的关注,我想根据 Android 操作系统版本来划分我的解释:

- Version 2.3 or lower:Yes application is as simple to make as guided by Pankaj Kumarand it will work for the above mentioned Android OS version and lower.

- 版本 2.3 或更低:是的,应用程序的制作与Pankaj Kumar 的指导一样简单,适用于上述 Android 操作系统版本及更低版本。

- Version 4.0 & up:Application will fail and not work. Yes, as warned by Android Dev Guys, from this version and up, you will not be able to read Messaging contents as I have tried it so your application will not work on coming Android releases. You can only get the numbers of them like: inbox, sent, outbox failed etc... but you cannot modify or read contents.

- 4.0 及以上版本:应用程序将失败且无法工作。是的,正如 Android 开发人员所警告的那样,从这个版本开始,您将无法阅读 Messaging 内容,因为我已经尝试过了,因此您的应用程序将无法在即将发布的 Android 版本上运行。您只能获取它们的编号,例如:收件箱、已发送、发件箱失败等……但您无法修改或阅读内容。

- Version > 3.0 & < 4.0 :Never tested and tried.

- 版本 > 3.0 & < 4.0:从未测试和尝试过。

Hope this information helps you and saves your time for going on a dead end route :)))

希望这些信息可以帮助您并节省您走死路的时间:)))

回答by Vipul Shah

Here you go

干得好

SMS Database has following Columns

SMS 数据库具有以下列

06-19 17:41:19.723: V/vipul(25223): _id
06-19 17:41:19.723: V/vipul(25223): thread_id
06-19 17:41:19.723: V/vipul(25223): address
06-19 17:41:19.723: V/vipul(25223): person
06-19 17:41:19.723: V/vipul(25223): date
06-19 17:41:19.723: V/vipul(25223): protocol
06-19 17:41:19.723: V/vipul(25223): read
06-19 17:41:19.723: V/vipul(25223): status
06-19 17:41:19.723: V/vipul(25223): type
06-19 17:41:19.723: V/vipul(25223): reply_path_present
06-19 17:41:19.723: V/vipul(25223): subject
06-19 17:41:19.723: V/vipul(25223): body
06-19 17:41:19.723: V/vipul(25223): service_center
06-19 17:41:19.723: V/vipul(25223): locked
06-19 17:41:19.723: V/vipul(25223): error_code
06-19 17:41:19.723: V/vipul(25223): seen
06-19 17:41:19.723: V/vipul(25223): deletable
06-19 17:41:19.723: V/vipul(25223): hidden
06-19 17:41:19.723: V/vipul(25223): group_id
06-19 17:41:19.723: V/vipul(25223): group_type
06-19 17:41:19.723: V/vipul(25223): delivery_date
06-19 17:41:19.723: V/vipul(25223): date_sent

Below snippet marks all SMS as Unread you can chnage it to match the id and only make unread that SMS

下面的代码片段将所有短信标记为未读,您可以更改它以匹配 id 并且只使该短信未读

package org.vipul;

import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class SMSSampleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Uri uri = Uri.parse("content://sms/inbox");
        Cursor cursor = managedQuery(uri, null, null, null, null);

        for (int i = 0; i < cursor.getColumnCount(); i++) {
            Log.i("vipul", cursor.getColumnName(i));
        }

        if (cursor.moveToFirst()) {
            do {

                String id = cursor.getString(0);

                ContentValues contentValues = new ContentValues();
                contentValues.put("read", false);
                getContentResolver().update(uri, contentValues, "_id=?",
                        new String[] { id });
                contentValues.clear();
            } while (cursor.moveToNext());

        }
    }
}

Finally add android.permission.READ_SMSans android.permission.WRITE_SMSin manifest

最后在清单中添加android.permission.READ_SMSansandroid.permission.WRITE_SMS

回答by JesusS

There is an app called "Mark as Unread", published by Christian Asbj?rn Skogsberg (check for it) so i guess it is possible.

有一个名为“标记为未读”的应用程序,由 Christian Asbj?rn Skogsberg 发布(检查它)所以我想这是可能的。