Can Not Attach Pdf Into Mail In Android
I am trying to create a pdf and send via email. Now I have sucessfully completed the pdf generation. When I try to attach the pdf into mail and send, I am getting error. I am tryin
Solution 1:
So Finlay I got the solution(Tips given by @CommonsWare)..
sendMail(Uri.fromFile(emailFilePath));
Send email Method:-
private void sendMail(Uri URI) {
try {
String email = emailFromDB;
String subject = "Report For the day " + getDateTime();
String message = "Report For the day " + getDateTime();
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("application/pdf");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { email });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,subject);
if (URI != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, URI);
}
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(Intent.createChooser(emailIntent,"Sending email..."));
} catch (Throwable t) {
Toast.makeText(this,
"Request failed try again: " + t.toString(),
Toast.LENGTH_LONG).show();
}
}
Here I have removed emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
and get the URI like Uri.fromFile(emailFilePath)
. This solved my problem. Thanks to @CommonnsWare..!!!
Post a Comment for "Can Not Attach Pdf Into Mail In Android"