当前位置: 动力学知识库 > 问答 > 编程问答 >

email - Android Send Intent attaching photo from sdcard as 0 length file

问题描述:

I know a variant of this question was asked before

trying-to-attach-a-file-from-sd-card-to-email

But the solution offered, i.e. a reboot doesn't seem to do it for me. I have seen a good number of group postings which support this being a problem. I can only assume the OP for the linked to question made some other changes, possibly to the manifest which allowed his code to work.

The behaviour I am seeing is the Email intent handling the attachment of the jpeg from the sdcard but dealing with it as a 0 length file which is discarded when sent. I have tried setType as jpeg/image and image/jpeg as I have seen it expressed both ways.

Intent sendIntent = new Intent(Intent.ACTION_SEND);

sendIntent.setType("jpeg/image");

sendIntent.putExtra(Intent.EXTRA_EMAIL, "[email protected]");

sendIntent.putExtra(Intent.EXTRA_SUBJECT, R.string.email_subjectStart +

mWhatYouSpotted.getSelectedItem().toString() +

R.string.email_subjectEnd);

sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:/"+ sPhotoFileName));

sendIntent.putExtra(Intent.EXTRA_TEXT, sEmailBody);

startActivity(Intent.createChooser(sendIntent, "Email:"));

Here is the adb logcat I got when I last tested:

V/DumbDumpersMain( 3972): sPhotoUri=file://sdcard/DumbDumpers/DumbDumper.jpg 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://gmail-ls/labels/[email protected](null, null) D/Gmail ( 2507): URI FOUND:file://sdcard/DumbDumpers/DumbDumper.jpg

I have been banging my head against this one for over a week now and still cannot determine what is wrong. Any ideas?

网友答案:

Should have done more searching here before posting; problem sending an email with an attachment programmatically solved it for me. I only have file://sdcard/DumbDumpers/DumbDumper.jpg, which annoyingly still looks like I have successfully attached the image. You need an extra / to make it work:

file:///sdcard/DumbDumpers/DumbDumper.jpg
       ^
网友答案:

Your intent type is wrong. It should be

sendIntent.setType("image/jpg");
分享给朋友:
您可能感兴趣的文章:
随机阅读: