tags:

views:

42

answers:

1

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.(AbstractStringBuilder.java:85) at java.lang.StringBuilder.(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.

A: 

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
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
yes, the code above is from a working application. Can you post log?
Asahi
Thanks - I added the log to my question above.
jwenn
I got it. It was the image size. I resized it down and it worked.
jwenn