views:

41

answers:

2

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.

A: 

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.

Andrew Guenther
This actually is possible, see the code I recently posted.
Blu Dragon
+1  A: 

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;

}

Blu Dragon