2013-02-28 47 views
1

我正在開發一個應用程序,其中我要計算最後日期總計inbox SMS。我正在使用此代碼如何統計Android上的日期收件箱短信

TextView view = new TextView(this); 
Uri uriSMSURI = Uri.parse("content://sms/inbox"); 
long now = System.currentTimeMillis(); 
long last24 = now - 24*60*60*1000;//24h in millis 
String[] selectionArgs = new String[]{Long.toString(last24)}; 
String selection = "date" + ">?"; 
String[] projection = new String[]{"date"}; 
Cursor cur = getContentResolver().query(uriSMSURI, projection, selection, selectionArgs,null); 
String sms = String.valueOf(cur.getCount()); 
view.setText("Total incoming today SMS "+sms); 
setContentView(view); 

我能夠計算過去24小時收件箱短信,但我需要計數最後日期收件箱短信。像今天Date is 28/02/13,但我想統計總收件箱短信Date 27/02/13

請幫助我,我是新學習者,請提前致謝。

回答

2

嘗試設置選擇爲date between date('now', '-1 day') and date('now'),除去selectionArgs

更新:

Cursor cur = getContentResolver().query(uriSMSURI, projection, "datetime(date/1000, 'unixepoch') between date('now', '-1 day') and date('now')", null, null); 
+0

感謝您的答覆,但我不理解如何實現programmaticaly你在說什麼。 。 – IPL10 2013-02-28 09:14:02

+0

變化8行至'光標CUR = getContentResolver()的查詢(uriSMSURI,投影, 「日期之間的日期( '現在', '-1天')和日期( '現在')」,NULL,NULL);' – user711058 2013-02-28 09:18:27

+1

似乎日期提交從currentTimeMillis()毫秒,答案可能是:'遊標cur = getContentResolver()。日期('現在','')之間的查詢(uriSMSURI,投影,「日期時間(日期/ 1000,'unixepoch' -1天')和日期('現在')「,null,null);' – user711058 2013-02-28 09:51:48