我可以使用来自here和here的DK代码示例发送彩信。我想把图像放到MMSPart类中。我认为mimetype将是“image / jpeg”(纠正我,如果我完全关注它),但如何将图像放入Data参数 - 我是否需要将图像读入fileInputStream或bitmapfactory并设置它的.Data值?
更新 - 尝试了asahi的代码,我想我越来越近,但现在我收到内存不足的错误。这是来自logcat的信息..
- 首先是这个 -
Out of memory on a 3602732-byte allocation.
- 然后这个 -
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)
感谢您的帮助。
答案 0 :(得分:1)
您可以这样做:
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();