检查是否已读取新短信

发布于 2024-09-15 03:18:49 字数 310 浏览 1 评论 0原文

我正在为 HTC EVO 开发一个简单的应用程序,当收到新的短信时,它会闪烁备用通知 LED。我让这部分通过广播接收器工作得很好,但是当用户使用默认短信应用程序阅读消息时,我需要某种方法来关闭 LED。我不确定最好在接收器中还是在后台服务中执行此操作。我发现这个,这可能是什么我正在寻找,但我不知道如何使用它,因为我找不到任何说明或教程。

I am working on a simple app for the HTC EVO that blinks the alternate notification LED when a new text message is received. I have this part working great via a Broadcast Receiver but I need some way to turn the LED off when the user has read the message(s) using their default SMS app. I'm not sure if it is best to do this in the receiver or in a background service. I found this, which might be what I am looking for, but I have no idea on how to use it as I could not find any instructions or tutorials.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花落人断肠 2024-09-22 03:18:49

好吧,我已经编写了以下代码,我认为它可以满足我的需求。

private int getUnreadSMSCount()
{
    int count = 0;
    Uri smsURI = Uri.parse("content://sms");
    ContentResolver contentResolver = this.getContentResolver();
    Cursor cursor = contentResolver.query(smsURI, null, "read=0", null, null);
    if (cursor != null)
    {
        try
        {
            count = cursor.getCount();
        }
        finally
        {
            cursor.close();
        }
    }

    return count;

}

Alright, I have worked out the following code which I think will meet my needs.

private int getUnreadSMSCount()
{
    int count = 0;
    Uri smsURI = Uri.parse("content://sms");
    ContentResolver contentResolver = this.getContentResolver();
    Cursor cursor = contentResolver.query(smsURI, null, "read=0", null, null);
    if (cursor != null)
    {
        try
        {
            count = cursor.getCount();
        }
        finally
        {
            cursor.close();
        }
    }

    return count;

}

一梦浮鱼 2024-09-22 03:18:49

不幸的是,我不相信有办法做到这一点。

当您的 BroadcastReceiver 收到 Intent 时,它是 Intent 的副本,与默认短信应用程序相同。因此,你们每个人都拥有彼此独立的消息副本。

您可以设置自己的消息副本来阅读,但您将无法在默认短信应用程序中查看其状态。此外,默认应用程序不会发送消息已被读取的广播,所有数据都保存在本地。

实现这一点的唯一方法是编写消息应用程序的完整替代品。

抱歉,希望这对您有所帮助,如果您还有其他问题,请告诉我。

Unfortunately I do not believe there is a way to do this.

When your BroadcastReceiver receives the Intent it is a copy of the Intent, same with the default SMS app. So you each have copies of the message independent of eachother.

You can set your own copy of the message to read, but you will be unable to see its status in the default SMS app. Also, the default app does not send out a broadcast that the message has been read, all that data is kept locally.

The only way you would be able to implement this would be to write a full replacement of the Messaging app.

Sorry, I hope this helps, let me know if you have any other questions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文