您可以根据您的日期范围自己过滤结果。
int date = mCursor.getColumnIndex(CallLog.Calls.DATE);
while (mCursor.moveToNext()) {
String callDate = mCursor.getString(date);
Date callDayTime = new Date(Long.valueOf(callDate));
// filter by date
如果您的过滤条件足够简单(例如,您希望在两次之间调用),您可以形成一个只返回给定范围内的日期的查询。例如,要在今年 10 月 12 日中午到晚上 7 点接听所有电话:
Calendar cal = Calendar.getInstance();
cal.set(2013, Calendar.OCTOBER, 12, 12, 0, 0);
Date afterDate = cal.getTime();
cal.set(2013, Calendar.OCTOBER, 12, 19, 0, 0);
Date beforeDate = cal.getTime();
final String SELECT = CallLog.Calls.DATE + ">?" + " AND "
+ CallLog.Calls.DATE + "<?";
Cursor managedCursor = getContentResolver().query(
CallLog.Calls.CONTENT_URI,
new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION,
CallLog.Calls.TYPE, CallLog.Calls.NUMBER,
CallLog.Calls._ID },
SELECT,
new String[] { String.valueOf(afterDate.getTime()),
String.valueOf(beforeDate.getTime()) },
CallLog.Calls.DATE + " desc");
如果您想过滤中午和晚上 7 点之间的呼叫,我认为第一个循环是您最好的选择(您将需要使用大SELECT
子句或弄清楚如何从long
SQL 中的值获取小时。