开发者

Sending an email with an attachment from an application

I'm creating an app that has an "export" feature which converts the user's data into a CSV file, and allows the user to send it as an attachment to somebody (presumably themselves).

The CSV file is created successfully, but when I try to send the email, I encounter a problem. The device looks like it is going to send the email with the appropriate attachment, but when the email is received... there is no attachment at all...

Here is the code I am using to 开发者_StackOverflow社区send the email:

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


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


need the correct path for your file, if on SD card then...

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

Look here for addition information on setting the appropriate file path

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜