0

I implemented share code that looks like anything else found when you search on StackOverflow.

String pathToExportedFile = getPath();

// Export for share
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");

share.putExtra(Intent.EXTRA_STREAM,
  Uri.parse("file:///" + pathToExportedFile));

share.putExtra(Intent.EXTRA_SUBJECT, "See Attachment");

model.activity.startActivity(Intent.createChooser(share, "Select a way to Share"));

However, it only works for Facebook. When I choose gmail, it looks like it is attached but when I recepient of the email gets no attachment. When I do it through Twitter, it says it cannot find the attachment.

The image file that is attached resides in "sdcard\DCIM\Camera"

Please help,

-mL

Update:

My file path is good but it looks like gmail is garbage collecting it? Here are some select ADB logs:

02-01 16:36:46.720: D/Gmail(1896): Cached file:///mnt/sdcard/DCIM/Camera/1328132065637.jpg to /data/data/com.google.android.gm/cache/2012-02-01-16:36:46428133821.attachment
02-01 16:36:46.880: D/Gmail(1896): MailProvider.insert(): added local message 140
02-01 16:36:47.100: I/Gmail(1896): MainSyncRequestProto: lowestBkwdConvoId: 0, highestHandledServerOp: 554429, normalSync: true
02-01 16:36:49.900: I/Gmail(1896): MainSyncRequestProto: lowestBkwdConvoId: 0, highestHandledServerOp: 554462, normalSync: true
02-01 16:36:51.650: D/Gmail(1896): Cleaning up cached attachment: /data/data/com.google.android.gm/cache/2012-02-01-16:36:46428133821.attachment
02-01 16:36:51.650: D/Gmail(1896): Updating message 1392647555039793989. synced=true
02-01 16:36:52.230: I/Gmail(1896): MainSyncRequestProto: lowestBkwdConvoId: 0, highestHandledServerOp: 554477, normalSync: true

Anyone got a clue?

Mark Lapasa
  • 1,644
  • 4
  • 19
  • 37
  • I have not ever seen that twitter is allowing to share image. As it post tweets only. But you can add a URL of image – Arslan Anwar Feb 01 '12 at 20:18

1 Answers1

0

Similar question here: Trying to attach a file from SD Card to email

Also getting the same problem (...)

From adb logcat:

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/me@gmail.com(null, null)
D/Gmail   ( 2507):      URI FOUND:file://sdcard/DumbDumpers/DumbDumper.jpg

Looks like the email provider is attaching a 0 length file. When I check the filesystem the file is there and correct. The code which creates the image file is well finished prior to the attempt to email it.

(...)

Update

Path for me should have been

file:///sdcard/DumbDumpers/DumbDumper.jpg

you need the extra / as this points to the root directory, i.e.:

file:// + /sdcard/DumbDumpers/DumbDumper.jpg

combined as

file:///sdcard/DumbDumpers/DumbDumper.jpg

In the above snippet you need:

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

I hope this helps. It took me ages to debug.

Regards,
Finlay

Community
  • 1
  • 1
Waza_Be
  • 39,407
  • 49
  • 186
  • 260
  • Can you try: uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), FILENAME)); instead of using "file:///" – Waza_Be Feb 02 '12 at 06:04