0

Successfully Sent MMS with multiple images :

Followed these steps to Sent MMS and also to add image in andorid database.

Problem: is i have 3 image in 1 mms and dont know how save them all against single MMS in android database.

I have tried this to save multiple images in single MMS by modifying method in given reference.

private static Uri createPart(Context context, String id,
            ArrayList<SentMMSVo> sentMMS2) throws Exception {
        ContentValues mmsPartValue = new ContentValues();
        mmsPartValue.put("mid", id);
        mmsPartValue.put("ct", "image/png");
        mmsPartValue.put("cid", "<" + System.currentTimeMillis() + ">");
        Uri partUri = Uri.parse("content://mms/" + id + "/part");
        Uri res = context.getContentResolver().insert(partUri, mmsPartValue);
        Log.e(">>>>>>>", "Part uri is " + res.toString());

        for (int i = 0; i < sentMMS2.size(); i++) {
            // Add data to part
            OutputStream os = context.getContentResolver()
                    .openOutputStream(res);
            ByteArrayInputStream is = new ByteArrayInputStream(sentMMS2.get(i)
                    .getData());
            byte[] buffer = new byte[256];
            for (int len = 0; (len = is.read(buffer)) != -1;) {
                os.write(buffer, 0, len);
            }
            os.close();
            is.close();
        }
        return res;
    }

This Method will save single image. it save image 1 and then override the new image bytes to pervious image.

how to save multiple images in single MMS.

Community
  • 1
  • 1
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41

2 Answers2

0

Update Found solution:

To save mutiple image in single mms in android database. i just have to modify above like this.

Logic: we have to create multiple parts for single mms.

    private static Uri createPart(Context context, String id,
                ArrayList<SentMMSVo> sentMMS2) throws Exception {
            ContentValues mmsPartValue = new ContentValues();
            mmsPartValue.put("mid", id);
            mmsPartValue.put("ct", "image/png");


            for (int i = 0; i < sentMMS2.size(); i++) {
                // Add data to part
            mmsPartValue.put("cid", "<" + System.currentTimeMillis() + ">");
            Uri partUri = Uri.parse("content://mms/" + id + "/part");
            Uri res = context.getContentResolver().insert(partUri ,mmsPartValue);
            Log.e(">>>>>>>", "Part uri is " + res.toString());
                OutputStream os = context.getContentResolver()
                        .openOutputStream(res);
                ByteArrayInputStream is = new ByteArrayInputStream(sentMMS2.get(i)
                        .getData());
                byte[] buffer = new byte[256];
                for (int len = 0; (len = is.read(buffer)) != -1;) {
                    os.write(buffer, 0, len);
                }
                os.close();
                is.close();
            }
            return res;
        }
Sohail Zahid
  • 8,099
  • 2
  • 25
  • 41
-1

this may help you out, this tutorial demonstrates how to send multiple images from SD card.

https://www.youtube.com/watch?v=55hRGBJ1-2E

Andy the android
  • 169
  • 1
  • 2
  • 16