我也遇到了同样的问题
代码:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"me@gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"go on read the emails");
Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:/"+ sPhotoFileName));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ sPhotoFileName));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
从adb logcat中:
V/DumbDumpersMain( 3972): sPhotoUri=file:
I/ActivityManager( 56): Starting activity: Intent { action=android.intent.action.CHOOSER comp={android/com.android.internal.app.ChooserActivity} (has extras) }
I/ActivityManager( 56): Starting activity: Intent { action=android.intent.action.SEND type=jpeg/image flags=0x3000000 comp={com.google.android.gm/com.google.android.gm.ComposeActivityGmail} (has extras) }
I/ActivityManager( 56): Starting activity: Intent { action=android.intent.action.SEND type=jpeg/image flags=0x2800000 comp={com.google.android.gm/com.google.android.gm.ComposeActivity} (has extras) }
D/gmail-ls( 120): MailProvider.query: content:
D/Gmail ( 2507): URI FOUND:file:
看起来电子邮件提供商附加了一个长度为0的文件。当我检查文件系统时,文件存在且正确。创建图像文件的代码在尝试发送电子邮件之前已经完成。
有人在没有进行神奇重启的情况下解决了这个问题吗?(我已经尝试过了)
更新
对于我来说路径应该是
file:///sdcard/DumbDumpers/DumbDumper.jpg
你需要额外的/
,因为这指向根目录,即:
file://
+/sdcard/DumbDumpers/DumbDumper.jpg
组合为
file:///sdcard/DumbDumpers/DumbDumper.jpg
在上面的片段中,你需要:
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName))