开发者

Sending MMS using httpConnection - Add Image to PDU

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(Activ开发者_运维问答ityThread.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.


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(); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜