如何计算android中的最后日期收件箱短信

时间:2013-02-28 07:55:18

标签: android date sms inbox

我正在开发一个应用程序,其中我想计算最后一个日期总计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小时的收件箱短信,但我需要计算最后日期收件箱短信。像今天Date is 28/02/13,但我想计算Date 27/02/13的总收件箱短信。

请提前帮助我,我是新学员。

1 个答案:

答案 0 :(得分:3)

尝试将选择设置为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);