获取未读短信的数量数量、短信

2023-09-12 03:28:51 作者:祝你溺死在鱼缸

我怎样才能在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.

 
精彩推荐