1

I am trying to find the number of unread SMS messages I have received via Google Hangouts.I tried this answer (Using new Telephony content provider to read SMS), and modified the code to count unread messages. It returns 0 every time. If I try to get the read count, by switching "read = 0" to "read = 1", the count is still 0.

I realize this means I have an empty SMS inbox in Hangouts, but in reality I do not. Any ideas on what I might be doing wrong?

When I switch my default SMS app to Messenger, it gets the unread count without a problem.

Finally, this is the code I'm using:

 private int getUnreadMessageCount() {
        Cursor c = getContentResolver().query(Telephony.Sms.Inbox.CONTENT_URI, null, "read = 0", null, null);
        int unreadCount = c.getCount();
        c.close();
        return unreadCount;
    }

Any help is truly appreciated. Thank you!

7
  • Your link is from 2010, I am not sure this is still possible now. Also, just to be sure, did you request the permission to read SMS to the user (API > 23) ?
    – maxoumime
    Jan 20, 2017 at 0:08
  • I did, yes, (edited the question to include that now). Do you how to do this in 2017?
    – Miki P
    Jan 20, 2017 at 0:39
  • 1
    READ_SMS is a dangerous permission now, you will need to ask for the permission at runtime. As for listing SMS the 2017 way, you will have to wait for someone else to answer :). But first try with this permission system, or manually grant the permission on the app settings.
    – maxoumime
    Jan 20, 2017 at 0:44
  • That's still how you query the SMS Provider. If your inbox is empty, but Hangouts is showing messages, then I suspect your problem is Hangouts. It does something funky with messaging all around when it's the default. I don't use it, so I've never had a chance to pin down exactly what it does. To test, you might temporarily set your default to a different SMS app - the basic Messenger, if you have it - send yourself some texts, and do your query again. I'd also suggest querying the base content://sms URI, with a null selection, to see if you've got any kind of messages there at all.
    – Mike M.
    Jan 20, 2017 at 15:47
  • Yep, so it seems to get the count when Messenger is the default. No such luck for Hangouts.
    – Miki P
    Jan 20, 2017 at 17:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.