user5326268
user5326268

Reputation:

Android parse query - Complex where clause

I'm having a small issue with a uri parse query. I'm almost there, or at least I think I am, but I just lack the final touch.

What I want to do

Ideally, I'd like to have the latest message recieved for each contact, in the last 24 hours.

What I have achieved so far

Getting every message recieved in the last 24 hours.

Code for the query is bellow:

Uri uri = Uri.parse("content://sms/inbox");
    long date = new Date(System.currentTimeMillis() - 24 * 3600 * 1000).getTime();

    Cursor c= getContentResolver().query(uri, null,"date" + ">?",new String[]{""+date},"date DESC");

I'm feeling there is just one small thing to add to the query for it to return what I want to. But I can't wrap my mind around it.

Upvotes: 0

Views: 225

Answers (1)

Android Developer
Android Developer

Reputation: 466

Try this,

Uri uri = Uri.parse("content://sms/inbox");

Date date = new Date();
Calendar cal = Calendar.getInstance();      
cal.setTime(date);      
cal.add(Calendar.DATE, -1);     

Cursor c= getContentResolver().query(uri, null,"date" + " > ?",new String[]{""+cal.getTimeInMillis()},"date DESC");

Hope it will help you

Upvotes: 0

Related Questions