尝试将文件从 SD 卡附加到电子邮件 [英] Trying to attach a file from SD Card to email

查看:29
本文介绍了尝试将文件从 SD 卡附加到电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试启动 Intent 以发送电子邮件.所有这些都有效,但是当我尝试实际发送电子邮件时,发生了一些奇怪"的事情.

I am trying to launch an Intent to send an email. All of that works, but when I try to actually send the email a couple 'weird' things happen.

这里是代码

Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("image/jpeg");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Photo");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/dcim/Camera/filename.jpg"));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the photo");
startActivity(Intent.createChooser(sendIntent, "Email:"));

因此,如果我使用 Gmail 菜单上下文启动它会显示附件,让我输入电子邮件的收件人,然后编辑正文 &主题.没什么大不了.我点击发送,它发送.唯一的问题是附件没有被发送.

So if I launch using the Gmail menu context It shows the attachment, lets me type who the email is to, and edit the body & subject. No big deal. I hit send, and it sends. The only thing is the attachment does NOT get sent.

所以.我想,为什么不尝试使用电子邮件菜单上下文(用于我手机上的备份电子邮件帐户).它显示附件,但正文或主题中根本没有文本.当我发送它时,附件发送正确.那会让我相信有些事情是完全错误的.我是否需要在 Manifest 中获得新的许可才能发送带有附件的电子邮件?我做错了什么?

So. I figured, why not try it w/ the Email menu context (for my backup email account on my phone). It shows the attachment, but no text at all in the body or subject. When I send it, the attachment sends correctly. That would lead me to believe something is quite wrong. Do I need a new permission in the Manifest launch an intent to send email w/ attachment? What am I doing wrong?

推荐答案

也遇到同样的问题

代码:

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:

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

电子邮件提供商似乎附加了一个长度为 0 的文件.当我检查文件系统时,文件在那里并且是正确的.创建图像文件的代码在尝试通过电子邮件发送之前已经完成.

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.

有人在没有神奇重启的情况下解决了这个问题(我已经试过了)?

Anyone fixed this without magic reboots (I've already tried that)?

问候,

更新

我应该走的路

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

你需要额外的 / 因为它指向根目录,即:

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

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

合并为

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.

问候,
芬莱

这篇关于尝试将文件从 SD 卡附加到电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆