2

在查询 Android 的 MMS-SMSContent Provider时,日期列对于 MMS 和 SMS 有不同的纪元时间值。

ContentResolver contentResolver = getContentResolver();
final String[] projection = new String[] { "body", "person", "sub",
            "subject", "retr_st", "type", "date" + " as " + "d", "ct_cls", "sub_cs",
            "_id", "read", "ct_l", "st", "msg_box", "reply_path_present",
            "m_cls", "read_status", "ct_t", "status", "retr_txt_cs",
            "d_rpt", "error_code", "m_id", "date_sent", "m_type", "v",
            "exp", "pri", "service_center", "address", "rr", "rpt_a",
            "resp_txt", "locked", "resp_st", "m_size" };
String sortOrder = "date";
Uri uri = Uri.parse("content://mms-sms/conversations/");
Cursor c = contentResolver.query(uri, projection, null, null, sortOrder);

String messageDate = c.getString(c.getColumnIndex("date"));

在 的情况下MMS,保存在 messageDate 变量中的纪元时间为 10 位长。但是,在 的情况下,SMS保存在 messageDate 变量中的纪元时间是 13 位长。

当尝试按日期排序时,这会成为一个问题,因为当按日期排序时,MMS消息显示在消息之前。SMS

有什么方法可以查询Content Provider并获取所有消息(MMSSMS)按日期正确排序?

4

1 回答 1

2

看起来按日期对消息进行排序的方法,无论消息是彩信还是短信,都是将排序顺序更改normalized_date为如下:

String sortOrder = "normalized_date";
于 2013-01-06T07:12:06.130 回答