views:

2294

answers:

2

Hi All,

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?

+1  A: 

Should have done more searching here before posting. This article didn't come up on any of my searches. Seems iphone vs g1 are the hot topics and are modded up.

"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

This forum is great. Just asking a question makes me brainier!

Regards,

Finlay

Finlay
A: 

Your intent type is wrong. It should be

sendIntent.setType("image/jpg");
Robert Foss