Unable To Attach An Attachment With Email In Android
I am trying to send an email with an attachment, I have created a pdf file as well as a text file, for attaching a text file and sending an email i am using this code email.setOnCl
Solution 1:
Solution 2:
Try this code for attach file with email client.
Filefile=newFile(path);
UripngUri= Uri.fromFile(file);
IntentemailIntent=newIntent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,newString[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_BCC,newString[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);
Path should be like below.
finalStringpath= Environment.getExternalStorageDirectory().toString()+ "/.....your_path";
Solution 3:
For attaching the PDF you need to set the type as "application/pdf"
and for text file "text/plain"
below :
FileexternalStorage= Environment.getExternalStorageDirectory()+File.separator+"Screenwriter"+File.separator+path;
Uriuri= Uri.fromFile(newFile(externalStorage.getAbsolutePath() + "/" + "yourfilename.pdf"));
IntentemailIntent=newIntent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Text");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
Post a Comment for "Unable To Attach An Attachment With Email In Android"