I am writing an app which needs runs everyday and should read the last days(previous day) call logs.
I wrote the code to fetch all the call logs with help from link but how can I optimize it to read only yesterdays call log from DB.
Thanks
I am writing an app which needs runs everyday and should read the last days(previous day) call logs.
I wrote the code to fetch all the call logs with help from link but how can I optimize it to read only yesterdays call log from DB.
Thanks
I found the answer myself
public Loader<Cursor> onCreateLoader(int loaderID, Bundle args) {
Log.d("CallLogs", "onCreateLoader() >> loaderID : " + loaderID);
switch (loaderID) {
case URL_LOADER:
String mSelectionClause = android.provider.CallLog.Calls.DATE+ " >= ?";
String[]mSelectionArgs = {createDate()};
// Returns a new CursorLoader
return new CursorLoader(
mContext, // Parent activity context
CallLog.Calls.CONTENT_URI, // Table to query
null, // Projection to return
mSelectionClause, // No selection clause
mSelectionArgs, // No selection arguments
CallLog.Calls.DATE + " desc" // Default sort order
);
default:
return null;
}
}
public String createDate()
{
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -1);
return String.valueOf(calendar.getTimeInMillis());
}