1

I am developing an SMS-MMS vault application for android. Its purpose will be to correct a couple of vulnerabilities existing in Android, as well as creating a "safe" communication space between certain contacts (Encrypted SMS and MMS).

I have implemented all the intended functionalities, except the functionality to receive MMS. I have found out no documentation on this matter. I have been reading a lot of code from other apps that implement this functionality and all of them wait for the stock application to receive the MMS and then retrieve it, which is not what I'm looking for, for my application is meant to be the default one.

So, here begs my question:

After receiving the MMS intent, how do I parse the Image and the Text?

1 Answers1

0

So what you can do to get pictures is go I get the MMS's id and go through ("content://mms/part") do a type check:

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


//is type a picture
if ("image/jpeg".equals(type) || "image/bmp".equals(type)
    || "image/gif".equals(type) || "image/jpg".equals(type)
    || "image/png".equals(type)) {
                   getMmsImage(partId); // load in your picture
      }

Now you that you have the part ID you know the picture's location so you can load it in using anything you want for example if you just want it as a bitmap you can do:

public Bitmap getMmsImage(String _id, Context context) {

        Uri partURI = Uri.parse("content://mms/part/" + _id);
        InputStream is = null;
        Bitmap bitmap = null;
        try {
            is = context.getContentResolver().openInputStream(partURI);
            bitmap = BitmapFactory.decodeStream(is);

        } catch (Exception e) {// probably should do an ioException around here}
        finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {}
            }
        }
        return bitmap;
    }

Now I would like to point out that if you wanted animated gifs this would not work, it would load the gifs but they would be still images. if you want them animated you could use something like Glide and give it the path location for the uri. Glide takes a while to load gifs though, just fair warning.

As for Receiving MMS, you could always use an Observer and load in the added message whenever the observer say there was a change... Or use a broadcast receiver if you want it to be the default messenger.

John Saunders
  • 86
  • 2
  • 5