我在查詢CallLog.Calls
內容提供商的詳細呼叫。我做這種事按當前日期查詢CallLog.Calls
Cursor managedCursor = cr.query(CallLog.Calls.CONTENT_URI, null,
null, null, null);
通過這種方式,我得到所有的通話記錄。但現在我想通過當前日期進行查詢,以便只獲取當前日期calllogs。應該如何解決這個問題?
我在查詢CallLog.Calls
內容提供商的詳細呼叫。我做這種事按當前日期查詢CallLog.Calls
Cursor managedCursor = cr.query(CallLog.Calls.CONTENT_URI, null,
null, null, null);
通過這種方式,我得到所有的通話記錄。但現在我想通過當前日期進行查詢,以便只獲取當前日期calllogs。應該如何解決這個問題?
試試這個:
//With this method you will get the timestamp of today at midnight
public long getTodayTimestamp(){
Calendar c1 = Calendar.getInstance();
c1.setTime(new Date());
Calendar c2 = Calendar.getInstance();
c2.set(Calendar.YEAR, c1.get(Calendar.YEAR));
c2.set(Calendar.MONTH, c1.get(Calendar.MONTH));
c2.set(Calendar.DAY_OF_MONTH, c1.get(Calendar.DAY_OF_MONTH));
c2.set(Calendar.HOUR_OF_DAY, 0);
c2.set(Calendar.MINUTE, 0);
c2.set(Calendar.SECOND, 0);
return c2.getTimeInMillis();
}
String timestap = String.valueOf(getTodayTimestamp());
Cursor managedCursor = cr.query(CallLog.Calls.CONTENT_URI, CallLog.Calls.DATE + ">= ?", new String[]{timestamp}, null);
我相信這已經回答了[這裏](http://stackoverflow.com/questions/5516423/calllog-calls-query-by-date) – Andrei