Etienne Lawlor
Etienne Lawlor

Reputation: 6697

Date column varies in length between MMS and SMS

When querying Android's MMS-SMS Content Provider, the date column has different epoch time values for MMS as opposed to 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"));

In the case of MMS, the epoch time that gets saved in the messageDate variable is 10 digits long. However, in the case of an SMS, the epoch time that gets saved in the messageDate variable is 13 digits long.

This becomes an issue when trying to sort by date since the MMS messages show up before SMS messages when sorted by date.

Is there any way to query this Content Provider and get all messages (MMS or SMS) sorted by date correctly?

Upvotes: 2

Views: 1142

Answers (1)

Etienne Lawlor
Etienne Lawlor

Reputation: 6697

It looks like the way to sort messages by date, regardless of whether the message is an MMS or SMS, is to change the sort order to normalized_date as follows:

String sortOrder = "normalized_date";

Upvotes: 2

Related Questions