4

I'm implementing the methods discussed here: How to Read MMS Data in Android?

I'm trying to read SMS and MMS into a single listview. I'm doing pretty well, but when I try to sort I'm getting all of the SMS sorted together followed by all of the MMS sorted together.

Here is my code:

Cursor smsCursor = getContentResolver().query(Uri.parse("content://mms-sms/conversations/"), null, null, null, "date DESC");

Can anyone tell me how to combine the two sources or how to combine the MMS into the SMS conversations like the built in Android app does?

Edit: I noticed that the date of SMS has several more digits than the dates of MMS.

Edit 2: Adding "julianday()" like so:

Cursor smsCursor = getContentResolver().query(Uri.parse("content://mms-sms/conversations/"), null, null, null, "julianday(date) DESC");

Makes the MMS appear at the top of the list.

Community
  • 1
  • 1
Dawson Goodell
  • 418
  • 2
  • 5
  • 15

2 Answers2

7

try normalized_date desc instead of date desc for the order.

It should work.

j0k
  • 22,600
  • 28
  • 79
  • 90
mayu
  • 221
  • 2
  • 7
  • 1
    This seems to crash on a Galaxy Note 2 with Android 4.3. The error is `Caused by: android.database.sqlite.SQLiteException: no such column: normalized_date (code 1): , while compiling: SELECT * FROM threads ORDER BY normalized_date desc` . How can you determine if the normalized_date column does not exist? I have tested this on other versions of android without an issue. – Etienne Lawlor Apr 05 '14 at 21:18
  • I can't test it. So I am just guessing. Maybe you don't need this column. I think, the original column date is already normalized in both table. So you need to use a exception handler to check if the query has this column. But I am just guessing! – mayu Apr 12 '14 at 11:11
  • @toobsco42 what was class of this Exception? – Eloar Jan 07 '15 at 13:31
0

The real problem here seem's to be that in the Database, the date is not stored exactly the same Way for SMS and MMS.

So you'll need to first query the database looking just for the "date" field. (Not normalized_date that would crash on some devices).

Then sort your list programmaticly in Java, taking in account that for the MMS, the date needs to be multiplied by 1000 as stated here : How do the retrieve the date of the mms from content://mms.* Or here mms sent/recive date is always in 1970

Community
  • 1
  • 1
tchoum
  • 312
  • 1
  • 2
  • 10