我正在为 HTC EVO 开发一个简单的应用程序,它会在收到新短信时闪烁备用通知 LED。我让这部分通过广播接收器工作得很好,但是当用户使用他们的默认 SMS 应用程序阅读消息时,我需要一些方法来关闭 LED。我不确定最好是在接收器中还是在后台服务中执行此操作。我找到了 this ,这可能是我正在寻找的,但我不知道如何使用它,因为我找不到任何说明或教程。
最佳答案
好的,我已经制定了以下代码,我认为可以满足我的需求。
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;
关于android - 检查是否已读取新的 SMS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3542580/