When I do below code without that comparison it works, but with that comparison it fails.
Thanks to Oleg Vaskevich , Updated code with his points .
And date range is 1-31 unlike month 0-11
And Date(int,int,int) replaced with Date(long)
edited code
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MONTH, -1);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);
int day=cal.get(Calendar.DATE); // for dynamic reset rates
callSince.setText("since(dd/mm/yyyy) :" + day + "/" + (month+1) + "/" + year );
// month+1 because month {0-11}
Date resetDateDate = new Date(cal.getTimeInMillis());
Calendar resetDateCal = Calendar.getInstance();
resetDateCal.setTime(resetDateDate);
String resetDate = String.valueOf(resetDateCal.getTimeInMillis());
/*
* CALL INCOMING
*/
projection = new String[] {CallLog.Calls.DURATION };
selection = CallLog.Calls.TYPE + "=? AND " + CallLog.Calls.DATE + " >=?" ;
selectionArgs = new String[] { (String.valueOf(CallLog.Calls.INCOMING_TYPE)) , (resetDate) };
try
{
Cursor cIn = getContentResolver().query(CallLog.Calls.CONTENT_URI, projection, selection, selectionArgs, sortOrder);
startManagingCursor(cIn);
You can see here that subtracting 1 from January results in -1, not December. To resolve this, use the
java.util.Calendarclass’s methodadd()to handle rolling over the proper fields. For example:Only after you’re done working with the calendar can you retrieve the actual fields of the calendar.