获取未读短信的数量 [英] Get number of unread sms

查看:224
本文介绍了获取未读短信的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能在Android的未读短信的数量?

How can I get the number of unread sms in android?

推荐答案

需要执行一个简单的查询短信的ContentProvider。以下是一个例子:

Need to execute a simple query to SMS ContentProvider. Here is a working example:

final Uri SMS_INBOX = Uri.parse("content://sms/inbox");

Cursor c = getContentResolver().query(SMS_INBOX, null, "read = 0", null, null);
int unreadMessagesCount = c.getCount();
c.deactivate();

您还需要READ_SMS权限:

You will also need the READ_SMS permission:

<uses-permission android:name="android.permission.READ_SMS" />

请记住,短信内容提供者是不实际的SDK的一部分,而这code不能保证在所有的过去,present和未来的设备。

Keep in mind that the SMS content provider isn't actually part of the SDK, and this code is not guaranteed to work on all past, present and future devices.

这篇关于获取未读短信的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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