【问题标题】:How to read last 3 sms from inbox in Android?如何从 Android 的收件箱中读取最后 3 条短信?
【发布时间】:2012-11-14 18:00:46
【问题描述】:

我用过这段代码

    String msgData = "";
    Cursor cursor = getContentResolver().query(Uri.parse("content://sms/inbox"), null, null, null, null);
    cursor.moveToFirst();

    do{

       for(int idx=0;idx<cursor.getColumnCount();idx++)
       {
           msgData += " " + cursor.getColumnName(idx) + ":" + cursor.getString(idx);
       }
    }while(cursor.moveToNext());    

..它可以工作,但它返回的数据比我想要的多。

如何阅读最后 3 条短信(只有短信和发件人)?

【问题讨论】:

标签: android sms inbox


【解决方案1】:

只需按日期对结果进行排序并使用限制子句:

getContentResolver().query(SMS_INBOX, new String[] {body, address}, 
    null, null, "date desc limit 3");

【讨论】:

  • 如何只读这个:地址:+48505073421 正文:短信
  • 使用String string = "address: " + cursor.getString(1) + " body: " + cursor.getString(0);
  • 请通读Cursor's documentation,你会发现moveToPosition()会帮你做到这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-08
  • 2012-03-12
  • 1970-01-01
相关资源
最近更新 更多