1

このリンクから送信された mms のテキストと画像を取得する方法に関する情報を取得しました: How to Read MMS Data in Android? .

しかし、送信された mms の日付を取得する方法がわかりません。

content://mms/part ではなく、content://mms を調べる必要があることはわかっています。

これは、mms テキストを取得する方法です。

private String getMmsText(String id) {
        Uri partURI = Uri.parse("content://mms/part/" + id);
        InputStream is = null;
        StringBuilder sb = new StringBuilder();
        try {
            is = getContentResolver().openInputStream(partURI);
            if (is != null) {
                InputStreamReader isr = new InputStreamReader(is, "UTF-8");
                BufferedReader reader = new BufferedReader(isr);
                String temp = reader.readLine();
                while (temp != null) {
                    sb.append(temp);
                    temp = reader.readLine();
                }
            }
        } catch (IOException e) {
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
        return sb.toString();
    }

次に、onCreate メソッドで、次のコードを使用して情報を取得します。

Cursor cursor = getContentResolver().query(uri, null, selectionPart,
                null, null);
        if (cursor.moveToFirst()) {
            do {
                String partId = cursor.getString(cursor.getColumnIndex("_id"));
                String type = cursor.getString(cursor.getColumnIndex("ct"));
                if ("text/plain".equals(type)) {
                    String data = cursor.getString(cursor
                            .getColumnIndex("_data"));

                    if (data != null) {
                        // implementation of this method above
                        body = getMmsText(partId);
                    } else {
                        body = cursor.getString(cursor.getColumnIndex("text"));
                    }
                }
            } while (cursor.moveToNext());
        }

        try {


            main.setText(body);
            img.setImageBitmap(bitmap);
        } catch (Exception e) {

            e.printStackTrace();
        }

日付値を取得するためにどこを変更できるか知りたいだけです。

いくつかの情報は本当に役に立ちます。

4

1 に答える 1

7

私は MMS にあまり詳しくありませんが、少なくともこのようなものから始められると思います

Cursor cursor = activity.getContentResolver().query(Uri.parse("content://mms"),null,null,null,date DESC);
count = cursor.getCount();
if (count > 0) 
{
    cursor.moveToFirst();
    long timestamp = cursor.getLong(2);
    Date date = new Date(timestamp);
    String subject = cursor.getString(3);
}

もちろん、完全にテストされていませんが、正しい方向に向ける必要があります。お役に立てれば!

編集 少し読んだ後、データを取得するときに、MMSメッセージのタイムスタンプに「バグ」がありました(おそらくまだあります)。ばかげた値 (エポックなど) になってしまった場合は、それを使用する前に * 1000 にする必要があります。余談ですが:)つまり:

long timestamp = (cursor.getLong(2) * 1000);
于 2014-01-30T15:35:26.607 に答える