0

i will attach the file but they show as a (0 bytes) below code is i used

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "ToDoNot.es");
emailIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(message));
File save_Image;
File temp=null;
save_Image=new File(ToDoViewActivity.this.getFilesDir(),"todofile");
temp=new File(save_Image,"tempfile"+String.valueOf(values.getAsInteger("rowid"))+".jpg");
Uri U = Uri.fromFile(new File("file://"+temp.getPath()));
emailIntent.putExtra(Intent.EXTRA_STREAM,U);
startActivity(Intent.createChooser(emailIntent, "Send email using"));

outpur: enter image description here

saravanan
  • 1,082
  • 1
  • 15
  • 30

3 Answers3

0

You don't type the file type... maybe it's becoz of this.

save_Image=new File(.........................."todofile.jpg")
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
0

The problem could be related with the getPath call on the temp file. Check the return value of that call, and make sure that the constructed URI that you are passing to putExtra matches one of the styles described in these documents:

Trying to attach a file from SD Card to email

https://superuser.com/questions/352133/what-is-the-reason-that-file-urls-start-with-three-slashes-file-etc

Most notably, you need 3 slashes after file:. Also, but unlikely, your issue may be caused by the MIME type you are setting with setType.

Community
  • 1
  • 1
damix911
  • 4,165
  • 1
  • 29
  • 44
0

I had this issue too - the problem is that you're trying to attach a file from your app's internal files directory, and the email intent doesn't have permissions to access it.

Copy it to the "external" storage first, then attach it to the email. That should work just fine.