Android: what to do with application/smil MIME type

Justin picture Justin · Feb 29, 2012 · Viewed 8.1k times · Source

I am using code similar to another SO post. But my MIME type for every MMS is "application/smil". How do I determine if the MMS contains a picture, audio, text, etc?

Here is the code I am using at the moment:

        String selectionPart = "mid =" + id;
        Uri ur = Uri.parse("content://mms/part");
        Cursor cur = getContentResolver().query(ur, null, selectionPart, null, null);
        if (cur.moveToFirst()) {
            do {
                String[] values = new String[cur.getColumnCount()];

                for (int i = 0; i < cur.getColumnCount(); i++) {
                    values[i] = cur.getString(i);
                }

                String partId = cur.getString(cur.getColumnIndex("_id"));
                String type = cur.getString(cur.getColumnIndex("ct"));

This is what is contained in values String[] for an audio MMS:

[56, 98, -1, application/smil, smil.xml, null, null, null, <0000>, smil.xml, null, null, null, <smil>
<smil>
  <head>
    <layout>
      <root-layout height="480px" width="320px"/>
      <region fit="meet" height="160px" id="Text" left="0" top="320" width="320px"/>
    </layout>
  </head>
  <body>
    <par dur="11000ms">
      <audio dur="11000ms" src="cid:171"/>
      <text region="Text" src="cid:172"/>
    </par>
  </body>
</smil>
]

Answer

wnafee picture wnafee · Oct 22, 2012

The problem is that you're assuming that your cursor only has 1 entry. It actually does not.

For MMS messages, you will find that there are 3 (or more) entries corresponding to the same mid. They are described below:

  1. One entry will correspond to the SMIL file. SMIL is a file format containing xml that helps an MMS viewer to know how to display the MMS (this is what you have printed above). The MIME type for this entry is application/smil if you look at the column called ct (acronym for content type)

  2. Another entry will correspond to the text file that contains any text within that MMS besides the attachment. The MIME type of this will be text/plain

  3. Lastly, you will find another entry that actually has the attachment. This attachment can have a variety of different MIME types depending on what the file is. If it happens to be a jpeg it will be image/jpeg, if png it will be image/png etc... (you get the point)

So, the problem was that you were assuming that the cursor has 1 row returned. If you iterate through 3 rows you will find what you are looking for

Typically, I would filter the _data column for non-empty value to get to the attachment row right away. (The _data column will contain the uri path for where the attachment is saved on the phone. That row will be null for all other rows that do not correspond to the MMS attachment. So you must search for the row that matches your mid and where _data column value is not null) When you find that row, you can just read the ct column of that row to find the MIME type of the row. That will tell you what type of file is being transferred in the MMS message be it image/xyz or audio/abc or video/qwe etc...