2011-11-03 78 views
1

我在查詢CallLog.Calls內容提供商的詳細呼叫。我做這種事按當前日期查詢CallLog.Calls

Cursor managedCursor = cr.query(CallLog.Calls.CONTENT_URI, null, 
       null, null, null); 

通過這種方式,我得到所有的通話記錄。但現在我想通過當前日期進行查詢,以便只獲取當前日期calllogs。應該如何解決這個問題?

+1

我相信這已經回答了[這裏](http://stackoverflow.com/questions/5516423/calllog-calls-query-by-date) – Andrei

回答

4

試試這個:

//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); 
+0

我嘗試這個解決方案它工作,但查詢應該是光標managedCursor = cr.query(CallLog.Calls.CONTENT_URI,null,CallLog.Calls.DATE +「> =?」,new String [] {timestamp},null); – ASH

+0

對不起,我寫的代碼,但我沒有測試它,所以有一個參數比接受的更多:) – rciovati

+0

此外小時格式應爲c2.set(Calendar.HOUR_OF_DAY,0)形式;支持24小時制。 – ASH