我的电话号码在mms地址字段的android对话

时间:2016-03-09 15:09:33

标签: android android-mms

我开发简单的短信/ mms客户端。使用sms一切都很好,但是对于mms,我在会话中遇到与地址字段相关的问题。

我有下一个加载对话的方法。有最后的短信和短信。

public static List<Conversation> getConversations(Context c) {
    List<Conversation> conversations = new ArrayList<>();
    Conversation conversation;

    Uri uri = Uri.parse("content://mms-sms/conversations/");
    Cursor cursor = c.getContentResolver().query(uri, null, null, null, "normalized_date DESC");

    if (cursor.moveToFirst()) {
        for (int i = 0; i < cursor.getCount(); i++) {
            conversation = new Conversation();
            conversation.setId(cursor.getString(cursor.getColumnIndexOrThrow("_id")));
            conversation.setThreadID(cursor.getString(cursor.getColumnIndexOrThrow("thread_id")));
            conversation.setDate(new Date(Long.valueOf(cursor.getString(cursor.getColumnIndexOrThrow("date")))));
            conversation.setReadType(ReadType.values()[Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow("read")))]);
            String type = cursor.getString(cursor.getColumnIndexOrThrow("type"));
            if (isSMS(type)) {
                conversation.setBody(cursor.getString(cursor.getColumnIndexOrThrow("body")));
                conversation.setNumber(cursor.getString(cursor.getColumnIndexOrThrow("address")));
                conversation.setMessageFromType(MessageFromType.values()[Integer.parseInt(type) - 1]);
            } else {
                Map<String, String> mmsContent = getMMSByID(c, conversation.getId());
                conversation.setBody(mmsContent.get("body"));
                conversation.setNumber(mmsContent.get("address"));
            }
            conversations.add(conversation);
            cursor.moveToNext();
        }
    }
    cursor.close();
    return conversations;
}

问题是,当我发送mms时,我的号码被用于解决对话领域。短信一切都还好。所以在那之后,我不知道谁是我在聊天的对手。

我也是以下一种方式加载mms号码

private String getNumber(Context c, String mmsdid) {
        String add = "";
        final String[] projection = new String[]{"address", "contact_id"};
        Uri.Builder builder = Uri.parse("content://mms").buildUpon();
        builder.appendPath(String.valueOf(mmsid)).appendPath("addr");
        Cursor cursor = c.getContentResolver().query(
                builder.build(),
                projection,
                null,
                null, null);
        if (cursor.moveToFirst()) {
            add = cursor.getString(cursor.getColumnIndex("address"));
        }
        return add;
    }

也许有人有同样的问题?或者有任何建议如何解决?

1 个答案:

答案 0 :(得分:1)

答案很简单,希望它可以帮助某人。一切都没关系,除了一部分。在选择参数中我应该添加

  

&#34;从151 =&#34;

  

&#34;从=&#34 + PduHeaders.TO

所以代码看起来像这样:

private static String getNumber(Context c, String id) {
        String add = "";
        final String[] projection = new String[]{"address"};
        Uri.Builder builder = Uri.parse("content://mms").buildUpon();
        builder.appendPath(String.valueOf(id)).appendPath("addr");
        Cursor cursor = c.getContentResolver().query(
                builder.build(),
                projection,
                "type="+PduHeaders.TO,
                null, null);
        if (cursor.moveToFirst()) {
            add = cursor.getString(cursor.getColumnIndex("address"));
        }
        cursor.close();
        return add;
    }