我正在查询CallLog.Calls
内容提供商的电话详情。我做了一些这样的事情
Cursor managedCursor = cr.query(CallLog.Calls.CONTENT_URI, null,
null, null, null);
通过这种方式,我获得了所有的通话记录。但现在我想查询当前日期,以便我只获得当前日期的calllogs。怎么应该接近这个?
答案 0 :(得分: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);