-5

I am trying to send a with attachment where the attachment file could be any type of file(like txt,image,pdf etc) from a sd card. I used these

String filelocation="file:/"+attachment_file_path1.getText().toString();    
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent.setType("text/plain");
String to[] = {"destination@yahoo.com"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "bodyyyyyyyyy");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(filelocation));
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "my mail");
startActivity(Intent.createChooser(emailIntent , "Send email..."));

N:B: if i print the attachment_file_path1.getText().toString() it shows like "/storage/sdcard0/myfolder/my.txt"

my email is sent to the destination but my attachment is not sent. How can i solve the problem??

kkkk
  • 121
  • 1
  • 1
  • 9
  • which error your getting? post some log messages – King of Masses May 26 '15 at 08:49
  • If you use `Intent.EXTRA_STREAM` to send attachment(s), use `emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, attachments);` where `attachments` must be of `ArrayList` object – ecle May 26 '15 at 09:06
  • http://stackoverflow.com/questions/4552831/how-to-attach-multiple-files-to-email-client-in-android – ecle May 26 '15 at 09:08

2 Answers2

0

Change your emailIntent.setType(text/plain) to emailIntent.setType("*/*") for allowing to send any file type.

Ankii Rawat
  • 2,070
  • 17
  • 17
0

Path format is :

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

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

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

combined as

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

In the above snippet you need:

emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));