Get number of unread sms

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();

You will also need the READ_SMS permission:

<uses-permission android:name="android.permission.READ_SMS" />

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.

Leave a Comment