Search code examples
androidsqlsqliteandroid-studiocursor

Set Date Criteria in getContentResolver().query for Uri.parse("content://sms/inbox")


I use

Uri.parse("content://sms/inbox")

when executing

getContentResolver().query

I want a selection that will always return messages from within the last 10 days of the current system date. Please help with the correct SQL statement.


Solution

  • Embarrassing to have to answer my own question but here goes...

    long daterr = new Date(System.currentTimeMillis() - 10L * 24 * 3600*1000).getTime();
    
    
    
    Cursor cursor = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"}, "Date > ? ", new String[]{""+daterr}, "date ASC");