How to query the MMS Log in Android
Asked Answered
M

1

9

In my app I need to query both the SMS and the MMS log to get the history of all incoming and outgoing messages. This code has worked wonderfully for SMS:

Cursor c = cr.query(Uri.parse("content://sms"), null, null, null, null);

But when I try the following I get completely different results:

Cursor c = cr.query(Uri.parse("content://mms"), null, null, null, null);

The SMS query returns data that includes the message address (phone number), contact name, message subject, message body, etc... The same query for MMS returns a bunch of nulls or numeric value fields that I can't make any sense of. I really need a list of all MMS messages currently on the phone with the phone number or contact ID associated with it, and if the message was an incoming or outgoing message. In the SMS query results I can get the phone number from the address field, and the incoming/outgoing type from the type field but neither of these exist when I query for MMS.

Is there a different content Uri that I need to query for this sort of MMS data? Any help would be greatly appreciated.

Edit: Just to clarify, I'm completely aware that this is an unsupported content provider. However since there is no supported way of doing this I'm fully willing to test and support this on a per phone/per OS version basis. Just to keep the discussion on track lets say this question is specific to Android 1.6 on an HTC Dream (G1) or HTC Magic (MyTouch). How would you accomplish this task on that specific phone and OS version? Or if it's not possible on those, but it is possible on Android 2.0 on a Motorola Droid, then I would find that information very helpful as well. But regardless, lets stick to the discussion of how to accomplish this task in a supported or unsupported manner and not let it devolve into a discussion of how we should all stay away from things that aren't supported by the API, which is something I find the Android discussion groups to be riddled with and which I feel provides little to no help whatsoever. If I'm using an unsupported method, that's fine, show me the supported method of accomplishing that task. If there is no supported method, then why does the API support allowing me to request permission to read SMS via android.permission.READ_SMS?

Mimosa answered 1/1, 2010 at 1:51 Comment(3)
Please bear in mind that neither of those are supported, and your application may break on various devices or with future Android releases. The SMS content provider is not part of the Android SDK, so device manufacturers are welcome to remove it, revise it, or otherwise muck it up, and the core Android team is welcome to do the same.Wiggle
I totally understand that. If you have some officially supported way of querying the SMS log I'd be happy to switch to it. In the mean time I'm just trying to work with what's available to me.Mimosa
See also: #2592030Shaughnessy
S
5

These are the content uris I've used in the past. You'll have to fiddle with the values you get back, and it's a long way from getting the parts of an MMS, but hopefully it'll help.

// root URI for MMS messages
static final String MMS_CONTENT_URI = "content://mms";

// root URI for MMS and SMS threads
public static final String MMS_SMS_CONTENT_URI = "content://mms-sms";

// URI of MMS inbox
public static final String RECEIVED_MMS_CONTENT_URI = MMS_CONTENT_URI + "/inbox";

// URI where sent MMSes are stored
public static final String SENT_MMS_CONTENT_URI = MMS_CONTENT_URI + "/sent";

// URI where sent MMSes are stored
public static final String MMS_PART_URI = MMS_CONTENT_URI + "/part";

// URI for incoming SMSes (also triggers on MMSes)
public static final String SMS_INBOX_URI = "content://sms/inbox";
Selfemployed answered 7/2, 2011 at 19:32 Comment(1)
Wait, what did you say was the difference between SENT_MMS_CONTENT_URI and MMS_PART_URI?Wedding

© 2022 - 2024 — McMap. All rights reserved.