尝试从SD卡上的文件,电子邮件卡上、电子邮件、文件、SD

2023-09-11 11:03:22 作者:没你的日子不好过。

我想推出一个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.

下面是code

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.

所以。我想,为什么不试试呢瓦特/电子邮件菜单上下文(在我的手机我的备份电子邮件帐户)。它显示了附接,但没有文字在所有在体内或主题。当我把它,附件正确发送。这将导致我相信事情是十分错误的。我需要在清单中推出的一个新的权限的意图发送电子邮件瓦特/附件?我究竟做错了什么?

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?

推荐答案

也越来越相同的问题

code:

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..."));

这是亚行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长度的文件。当我检查文件系统的文件是存在的,正确的。在code的创建图像文件以及之前以电子邮件的念头完成。

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)?

问候, 散热片

Regards, Fin

更新

路径对我来说应该是

文件:///sdcard/DumbDumpers/DumbDumper.jpg

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

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

文件:// + /sdcard/DumbDumpers/DumbDumper.jpg

组合成

文件:///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.

问候, 芬利