Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CallLog.Calls Query By Date

Tags:

android

I am querying CallLog.Calls content provider for call details. Everything works fine except when I try to query by dates. That is, to get call details for a particular date or date range etc. I know the date are stored as long (millisecond format) so I tried to convert the date first and then query by it, but I must be doing something wrong here. Here's the query I am running, pls note that it works well when I remove the "WHERE DATE =" part or replace it by something like "WHERE TYPE=" etc. So, how do I run a query to get call details for a date or date range? Any help on this? Thanks.

Cursor c = getContentResolver().query(CallLog.Calls.CONTENT_URI, null,
               CallLog.Calls.DATE + "<=?",
                new String[] { String.valueOf(dateSTR)}, ORDER_BY);
        startManagingCursor(c); 
like image 298
redGREENblue Avatar asked Dec 28 '22 22:12

redGREENblue


1 Answers

This is how i do it:

Cursor c = contentResolver.query(CallLog.Calls.CONTENT_URI,
                new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION,
                        CallLog.Calls.NUMBER, CallLog.Calls._ID },
                CallLog.Calls.DATE + ">?",
                new String[] { String.valueOf(resetDate.getTime())},
                CallLog.Calls.NUMBER + " asc");

resetDate is a Date variable, set to the beginning of the period i want to cover.

like image 150
alibi Avatar answered Dec 30 '22 13:12

alibi