我需要在 android 中发送彩信,所以给出了如下代码,drawable 中的图像首先保存在 sd 卡中,然后取回 SMS 正文,但是在单击“发送”按钮后,我得到了如下所示的图像。从 sd 卡下载的保存图像无法打开,我收到错误为“无效文件”。检查图像名称,一切都是小写字母。我哪里错了,请告诉我。
意图代码
private void doSendIntent(String subject, String text) {
try {
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
// sendIntent.setType("message/rfc822");
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
sendIntent.setType("image/png");
Bitmap bbicon;
bbicon = BitmapFactory.decodeResource(getResources(),
R.drawable.gicon);
String extStorageDirectory = Environment
.getExternalStorageDirectory().toString();
OutputStream outStream = null;
File f = new File(extStorageDirectory + "/Download/",
"gicon.png");
try {
outStream = new FileOutputStream(f);
bbicon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
}
File fl = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/Download/", "gicon.png");
Uri uri = Uri.fromFile(fl);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
this.cordova).getContext().getPackageName(), 0);
this.cordova.startActivityForResult(this, sendIntent, 0);
}
private Resources getResources() {
// TODO Auto-generated method stub
return null;
}
}
Logcat 错误
09-20 11:58:35.200: E/Mms/media(323): IOException caught while opening or reading stream
09-20 11:58:35.200: E/Mms/media(323): java.io.FileNotFoundException: /mnt/sdcard/Download/gicon.png (Permission denied)
09-20 11:58:35.200: E/Mms/media(323): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
09-20 11:58:35.200: E/Mms/media(323): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
09-20 11:58:35.200: E/Mms/media(323): at java.io.FileInputStream.<init>(FileInputStream.java:80)
09-20 11:58:35.200: E/Mms/media(323): at java.io.FileInputStream.<init>(FileInputStream.java:132)
09-20 11:58:35.200: E/Mms/media(323): at android.content.ContentResolver.openInputStream(ContentResolver.java:317)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.model.MediaModel.initMediaSize(MediaModel.java:280)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.model.MediaModel.<init>(MediaModel.java:77)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.model.RegionMediaModel.<init>(RegionMediaModel.java:40)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.model.RegionMediaModel.<init>(RegionMediaModel.java:35)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.model.ImageModel.<init>(ImageModel.java:63)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.data.WorkingMessage.changeMedia(WorkingMessage.java:464)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.data.WorkingMessage.setAttachment(WorkingMessage.java:365)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.ui.ComposeMessageActivity.addImage(ComposeMessageActivity.java:2663)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.ui.ComposeMessageActivity.addAttachment(ComposeMessageActivity.java:2799)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.ui.ComposeMessageActivity.handleSendIntent(ComposeMessageActivity.java:2728)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.ui.ComposeMessageActivity.initialize(ComposeMessageActivity.java:1757)
09-20 11:58:35.200: E/Mms/media(323): at com.android.mms.ui.ComposeMessageActivity.onCreate(ComposeMessageActivity.java:1685)
09-20 11:58:35.200: E/Mms/media(323): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-20 11:58:35.200: E/Mms/media(323): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
09-20 11:58:35.200: E/Mms/media(323): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
09-20 11:58:35.200: E/Mms/media(323): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
09-20 11:58:35.200: E/Mms/media(323): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
09-20 11:58:35.200: E/Mms/media(323): at android.os.Handler.dispatchMessage(Handler.java:99)
09-20 11:58:35.200: E/Mms/media(323): at android.os.Looper.loop(Looper.java:123)
09-20 11:58:35.200: E/Mms/media(323): at android.app.ActivityThread.main(ActivityThread.java:3683)
09-20 11:58:35.200: E/Mms/media(323): at java.lang.reflect.Method.invokeNative(Native Method)
09-20 11:58:35.200: E/Mms/media(323): at java.lang.reflect.Method.invoke(Method.java:507)
09-20 11:58:35.200: E/Mms/media(323): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-20 11:58:35.200: E/Mms/media(323): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-20 11:58:35.200: E/Mms/media(323): at dalvik.system.NativeStart.main(Native Method)