2015-10-13 55 views
0

我遇到一個uri解析查詢的小問題。我幾乎在那裏,或者至少我認爲我是,但我只是缺乏最後的感覺。Android解析查詢 - 複合體where子句

我想做

理想情況下,我想有每個聯繫人收到最新的消息,在過去的24個小時。

到目前爲止

我所取得的成就獲得在過去24小時內收到的每封郵件。

代碼查詢是波紋管:

Uri uri = Uri.parse("content://sms/inbox"); 
    long date = new Date(System.currentTimeMillis() - 24 * 3600 * 1000).getTime(); 

    Cursor c= getContentResolver().query(uri, null,"date" + ">?",new String[]{""+date},"date DESC"); 

我的感覺只有一個要添加到查詢它返回什麼,我想小東西。但是我無法圍繞它思考。

回答

0

試試這個,

Uri uri = Uri.parse("content://sms/inbox"); 

Date date = new Date(); 
Calendar cal = Calendar.getInstance();  
cal.setTime(date);  
cal.add(Calendar.DATE, -1);  

Cursor c= getContentResolver().query(uri, null,"date" + " > ?",new String[]{""+cal.getTimeInMillis()},"date DESC"); 

希望這將有助於你