1

我正在创建一个具有“导出”功能的应用程序,它将用户的数据转换为 CSV 文件,并允许用户将其作为附件发送给某人(可能是他们自己)。

CSV 文件创建成功,但是当我尝试发送电子邮件时,我遇到了问题。该设备看起来要发送带有适当附件的电子邮件,但是当收到电子邮件时......根本没有附件......

这是我用来发送电子邮件的代码:

final Intent email = new Intent(android.content.Intent.ACTION_SEND);

  email.setType("text/html");
  email.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.email_subject));
  email.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(getString(R.string.email_1)));

  email.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///" + getString(R.string.csv_title)));


  startActivity(Intent.createChooser(email, "Send mail..."));
4

3 回答 3

2
i've done for send any file from SD card with mail attachment..

Intent sendEmail= new Intent(Intent.ACTION_SEND);
       sendEmail.setType("rar/image");
       sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new        
         File("/mnt/sdcard/download/abc.rar")));
         startActivity(Intent.createChooser(sendEmail, "Email:"));
于 2013-04-01T13:50:21.677 回答
0

需要文件的正确路径,如果在 SD 卡上,则...

sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse 
("file://"+Environment.getExternalStorageDirectory()+getString(R.string.csv_title)"));

在此处查找有关设置适当文件路径的其他信息

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

于 2010-11-10T21:37:11.493 回答
0

GMail app accepts file:// Uris only if they are on the sdcard... and on an android 1.6 device I had even an issue with it accepting only file://sdcard/* Uris whereas the real external storage of this specific device is on another path.

Anyway, I have a real better behavior with attachments since I provide them through a ContentProvider.

于 2010-11-10T22:43:32.983 回答