在Android中阅读Sms对话

时间:2016-08-16 17:17:05

标签: android sms

我正在为Android开发一个短信应用程序,我需要阅读发送者和接收者之间的对话。

我已经尝试了所有我知道但仍然无法做到的事情。

Cursor c = getContentResolver(),query(Uri.parse("content://mms-sms/conversations?simple=true"), null,null,null,null);

上面的代码没有给出两个人之间的对话。 请帮我看看如何阅读对话。

1 个答案:

答案 0 :(得分:0)

我曾经使用过这样的代码,但不记得我从哪里得到它:

StringBuilder smsBuilder = new StringBuilder();
    final String SMS_URI_INBOX = "content://sms/inbox";
    final String SMS_URI_ALL = "content://sms/";
    try {
        Uri uri = Uri.parse(SMS_URI_INBOX);
        String[] projection = new String[]{"_id", "address", "person", "body", "date", "type"};
        Cursor cur = getActivity().getContentResolver().query(uri, projection, "address='33300'", null, "date desc");


        int index_Address = cur.getColumnIndex("address");
        int index_Person = cur.getColumnIndex("person");
        int index_Body = cur.getColumnIndex("body");
        int index_Date = cur.getColumnIndex("date");
        int index_Type = cur.getColumnIndex("type");
        String strAddress = cur.getString(index_Address);
        int intPerson = cur.getInt(index_Person);
        String strbody = cur.getString(index_Body);
        long longDate = cur.getLong(index_Date);
        int int_Type = cur.getInt(index_Type);

        smsBuilder.append("[ ");
        smsBuilder.append(strAddress + ", ");
        smsBuilder.append(intPerson + ", ");
        smsBuilder.append(strbody + ", ");
        smsBuilder.append(longDate + ", ");
        smsBuilder.append(int_Type);
        smsBuilder.append(" ]\n\n");

        cur.close();