Search code examples
androidsmssmsmanager

How to get unread message in my SMS app android


I have created an SMS app for all versions. I am using the cursor adapter for showing the Message and number. Things are working fine except that I am not able to differentiate the new messages?

How to fix this SMS unread part? I would like to BOLD them when I receive it. But I don't know how what is received.

What I am doing now:

In my SMS receiver I store the new numbers to local DB and then compare them with the SMS content provider. This works just fine, but then takes a lot of time to load the messages.

How to fix this up?

Thanks!


Solution

  • I solved the problem with a few trial and errors..

    Got the Read value for particular number and corresponding message( if "0" then bold them according).

    To mark read I did the following:

        Uri uri = Uri.parse("content://sms/inbox");
    String selection = "address = ? AND body = ? AND read = ?";
    String[] selectionArgs = {from, body, "0"};
    
    ContentValues values = new ContentValues();
    values.put("read", true);
    
    context.getContentResolver().update(uri, values, selection, selectionArgs);
    

    Hope it helps for people who are looking for solution...