你如何从Android设备获得所有的短信(收件箱)?

时间:2012-09-18 07:38:13

标签: android sms

  

可能重复:
  How can I read SMS messages from the inbox programmatically in Android?

我想从Android设备获取所有收件箱短信。我该怎么做?

1 个答案:

答案 0 :(得分:7)

您可以从以下方法获取收件箱邮件。

public List<String> getSMS(){
     List<String> sms = new ArrayList<String>();
        Uri uriSMSURI = Uri.parse("content://sms/inbox");
        Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);

        while (cur.moveToNext()) {
               String address = cur.getString(cur.getColumnIndex("address"));
               String body = cur.getString(cur.getColumnIndexOrThrow("body"));
              sms.add("Number: " + address + " .Message: " + body);  

          }
        return sms;

    }