我正在开发一个应用程序,我想在其中计算最后一个日期的总 inbox SMS
。我正在使用这段代码
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 小时的收件箱短信,但我需要计算最后日期的收件箱短信。就像今天一样,日期是 28/02/13
但我想计算 Date 27/02/13
的收件箱短信总数。
请帮助我,我是新手,在此先感谢。
最佳答案
尝试将选择设置为 date('now', '-1 day') 和 date('now') 之间的日期
,删除 selectionArgs
更新:
Cursor cur = getContentResolver().query(uriSMSURI, projection, "datetime(date/1000, 'unixepoch') between date('now', '-1 day') and date('now')", null, null);
关于android - 如何在android中计算最后一个日期收件箱短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15130280/