Can't retrieve MMS data

940 Views Asked by At

Context

I am trying to retrieve MMS data from Android, I can count the MMS from content://mms/ but when I want to get the MMS data then it's empty.

Problem

First I count the MMS like this:

Uri uri = Telephony.Mms.CONTENT_URI;  // content://mms/

Cursor cursor = contentResolver.query(uri, null, null, null, null);
int count = cursor.getCount();

Assuming I have 3 MMS, the count is equal to 3. No problem here.

Now I want to retrieve the data from each MMS, I found out (here and here) that I had to query the content://mms/part provider, that's what I did. The problem is that this cursor is always empty, I've tried many different ways:

Uri uri = Uri.parse("content://mms/part");
String selection = Telephony.Mms.Part.MSG_ID + " = " + id;
Cursor cursor = contentResolver.query(uri, null, selection, null, null);

// OR

Uri uri = Uri.parse("content://mms/part/" + id);
Cursor cursor = contentResolver.query(uri, null, null, null, null);

// OR

Uri uri = Uri.parse("content://mms/" + id "/part");
Cursor cursor = contentResolver.query(uri, null, null, null, null);

And each time, my cursor is empty.


Getting MMS id:

Cursor cursor= contentResolver.query(Telephony.Mms.CONTENT_URI, new String[]{"*"}, null, null, null);
if (cursor!= null) {
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            sms = createMmsFromCursor(cursor);
            cursor.moveToNext();
        }
        cursor.close();
    }
}

And then the createMmsFromCursor(cursor):

private final MMS createMmsFromCursor(Cursor cursor) {
    long id = cursor.getLong(cursor.getColumnIndex(Telephony.Mms._ID));
    // ...
    Map.Entry partValues = getDataFromMms(id);
    // ...
    return mms;
}

The getDataFromMms(id) will call the above code (where my problem is) using the id given in parameter.

Question

Am I correctly querying the content provider ? Or am I using the wrong provider Uri ? Maybe the MMS part Uri is different depending on the device, if so, how can I always point on the right Uri ?

1

There are 1 best solutions below

0
On

Not sure if you have found an answer yet. Here is what I have, and it is working (for me):

Uri uriMms = Uri.parse("content://mms/");
final String[] projection = new String[]{"*"};
Cursor cursor = contentResolver.query(uriMms, projection, null, null, null);
String id = cursor.getString(cursor.getColumnIndex("_id"));
String selectionPart = "mid=" + id;
Uri uri = Uri.parse("content://mms/part");
Cursor cursor2 = getContentResolver().query(uri, null, selectionPart, null, null);

Then do cursor2.moveToFirst()