2

シンプルな sms/mms クライアントを開発しています。SMS ではすべて問題なく動作しますが、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 を送信したときに、私の番号が会話のアドレス フィールドに入力されたことです。SMSですべて大丈夫です。だからチャットの相手が誰だかわからない。

また、次の方法で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;
    }

多分誰かが同じ問題を抱えていますか?または、それを解決する方法について何か提案はありますか?

4

1 に答える 1

1

答えはとても簡単でした。誰かの役に立てば幸いです。一部を除いてすべて問題ありません。選択パラメータに追加する必要があります

「から=151」

また

"from="+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;
    }
于 2016-03-15T14:29:32.587 に答える