2011-11-03 58 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