How to add .pdf extension when sending an attachment from Android?
I am trying to send a pdf as 开发者_StackOverflow社区an attachment from Android. Here is the code:
String[] mailto = {"me@gmail.com"};
Uri uri = Uri.parse("android.resource://com.mywebsite.sendemail/raw/mypdf");
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "My Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "My Body");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
Now this works but the problem is that the attachment is called mypdf instead of mypdf.pdf. I cannot figure out how to send it with it's extension... That's what I need help with. Thanks.
I am unconvinced what you want will be possible, since you are pulling the PDF from a resource. If you copy the PDF to a local file (with the correct extension) and send that, you should get the extension in the resulting message. But straight out of the resource...I suspect there's no way to add the extension.
When ever I attempt to use the .putExtra methodology it always crashes my application with a "Force Close" message. If I use something like: String mtUri = "mailto:someone@gmail.com?subject=Some Subject&body=Some text&"; Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(mtUri)); startActivity(intent);
It seems to work fine. I do still have the problem of attaching a file and could use some help figurint out the "attachment=file:///..." syntax.
Thanks,
精彩评论