如何检索从内容彩信日期://彩信。 [英] How do the retrieve the date of the mms from content://mms.

查看:328
本文介绍了如何检索从内容彩信日期://彩信。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有得到有关如何取回文字和从这个链接发送彩信图片的信息:的如何阅读彩信数据在Android中?

I did get the information on how to retrieve the text and the image for the mms sent from this link: How to Read MMS Data in Android?.

但我不知道如何检索已发送彩信的日期。

But I am not sure how to retrieve the date for the mms that was sent.

我知道我必须考虑的内容://彩信,而不是内容:// MMS /一部分。

I know I have to look into content://mms and not in content://mms/part.

这是Mothod检索彩信文本:

This is the Mothod to retrieve the mms text:

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方法,我用这个code,以获得信息:

and then, in the onCreate method, I use this code to get the info:

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();
        }

我只是想知道我在哪里可以修改得到的日期值。

I just want to know where can I make changes to get the date value.

一些信息会非常有帮助。

Some info will be really helpful.

推荐答案

我不是太熟悉MMS的,但我想像这样的事情就至少得拿到你开始

I'm not overly familiar with MMS's, but I'd imagine something like this would at least get you started

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);
}

这是完全未经测试的课程,但应该指向你在正确的方向。希望这有助于!

It's completely untested of course, but should point you in the right direction. Hope this helps!

修改
做一点阅读后,也曾经是(可能现在仍然是)一个错误,在MMS消息的时间戳,检索数据时。如果你结束了一个愚蠢的值(如时代),你就必须* 1000使用它之前。只是说句题外话:)即:

Edit After doing a bit of reading, there used to be (possibly still is) a "bug" with the timestamp in MMS messages, when retrieving the data. If you end up with a silly value (like the epoch), you'll have to * 1000 before using it. Just an aside :) I.e.:

long timestamp = (cursor.getLong(2) * 1000);

这篇关于如何检索从内容彩信日期://彩信。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆