SKB
SKB

Reputation: 137

Attachments in Email

I am developing an app which requires to send email to a person. Everything works fine except the attachment. And here is the piece of code for that

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

attach is the file i got by browsing in the phone. But the attachment is not being sent Please Help.

Thanx

Upvotes: 1

Views: 238

Answers (1)

Luminger
Luminger

Reputation: 2194

According to my blogpost found here:

Creating a mail on Android which the user may send with the app of his choice is widely spread on the net. But it isn't how you attach a file which will be send by googlemail.

The problem here is that the gmail app only want to send files which are located on the sdcard

Intent mail = new Intent(android.content.Intent.ACTION_SEND);
mail.setType("application/octet-stream");
mail.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {"[email protected]"});
mail.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
mail.putExtra(android.content.Intent.EXTRA_TEXT, "Message");
mail.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/file.txt"));
PrefAct.startActivity(Intent.createChooser(mail, "Send mail via..."));

As said gmail will refuse your attachment when the user sends the mail when the file isn't located on the ExternalStorage.

Upvotes: 1

Related Questions