0

i was able to send an MMS using DK's code sample from here and here. I'd like to put an image into the MMSPart class. I think the mimetype will be "image/jpeg" (correct me if I'm totally worng on that), but how to I put an image into the Data parameter - do I need to read the image into a fileInputStream or bitmapfactory and set the .Data value to it?

UPDATE - tried asahi's code and I think I'm getting closer, but now I'm getting an out of memory error. Here is the info from logcat..

--first this--

Out of memory on a 3602732-byte allocation.

--then this--

Uncaught handler: thread main exiting due to uncaught exception
java.lang.OutOfMemoryError
at java.lang.AbstractStringBuilder.<init>(AbstractStringBuilder.java:85)
at java.lang.StringBuilder.<init>(StringBuilder.java:69)
at java.util.Arrays.toString(Arrays.java:2659)
at com.market.mmsapp.HttpUtils.httpConnection(HttpUtils.java:88)
at com.market.mmsapp.slimMmsActivity.UploadFile(slimMmsActivity.java:132)
at com.market.mmsapp.slimMmsActivity.onCreate(slimMmsActivity.java:46)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
at android.app.ActivityThread.access$2100(ActivityThread.java:116)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4203)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
at dalvik.system.NativeStart.main(Native Method)

Thanks for any help.

Community
  • 1
  • 1
jwenn
  • 3
  • 3

1 Answers1

1

You can do something like this:

ByteArrayOutputStream os = new ByteArrayOutputStream();
Bitmap b =  Media.getBitmap(getContentResolver(), bitmapUri);

b.compress(CompressFormat.JPEG, 90, os);

mmsPart.Name = fileName;
mmsPart.MimeType = "image/jpeg";
mmsPart.Data = os.toByteArray(); 
Asahi
  • 13,378
  • 12
  • 67
  • 87
  • Thanks. I gave that a try, but now I'm getting a java.lang.OutOfMemory error. The image I am loading is 70K. I wonder if there is some limitation on the file size for the MMS. I am going to keep trying things. Has this ever worked for you? – jwenn Oct 16 '10 at 14:32
  • yes, the code above is from a working application. Can you post log? – Asahi Oct 16 '10 at 14:44
  • Thanks - I added the log to my question above. – jwenn Oct 16 '10 at 18:50
  • I got it. It was the image size. I resized it down and it worked. – jwenn Oct 17 '10 at 03:25
  • I know this was answered some time ago but did you notice if the images would arrive with a normal size? – zwebie Jan 16 '13 at 10:25
  • as it was answered some time ago... I'd say I did not notice anything abnormal back then. – Asahi Jan 16 '13 at 10:47
  • do you know if there's a limit to the size image I can send in a mms? – zwebie Jan 16 '13 at 11:49
  • 1
    sometimes operators impose limit on size of attachments. other than that - do not know – Asahi Jan 16 '13 at 13:16