Search code examples
androidsmsinbox

How check if sms/inbox is empty?


I'd like to know if we can write a short boolean test which return true if sms/inbox is empty or not.

Something like Databse("content://sms/inbox")==null?


Solution

  • Here's the code:

    // Retrieve a Cursor pointing to the sms list and the size of it.
    Uri uriSMSURI = Uri.parse("content://sms/inbox");
    Cursor cur = mContext.getContentResolver().query(uriSMSURI, null, null, null, null);
    boolean ret = cur.getCount() > 0;
    

    Remember to close the cursor afterwards.