【问题标题】:how to count last date inbox sms in android如何在android中计算最后一个日期收件箱短信
【发布时间】:2013-02-28 07:55:17
【问题描述】:

我正在开发一个应用程序,我想在其中计算最后日期总数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 的总收件箱短信。

请帮助我,我是新手,提前谢谢。

【问题讨论】:

    标签: android date sms inbox


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回复,但我不明白如何以编程方式实现您在说什么。
    • 将第 8 行更改为 Cursor cur = getContentResolver().query(uriSMSURI, projection, "date between date('now', '-1 day') and date('now')", null, null);
    • 似乎提交的日期是从 currentTimeMillis() 开始的毫秒数,答案可能是:Cursor cur = getContentResolver().query(uriSMSURI, projection, "datetime(date/1000, 'unixepoch') between date('now', '-1 day') and date('now')", null, null);
    • 最后一个工作正常。发自内心的感谢你,你真的很善良。再次感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多