How to add .pdf extension when sending attachments from Android?

I am trying to send a PDF as an attachment with 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 can’t figure out how to send it using this extension ... This is what I need help with. Thank.

+3
source share
2 answers

I'm not sure what you want because you are pulling a PDF from a resource. If you copy a PDF file to a local file (with the correct extension) and send it, you should receive the extension in the received message. But right from the resource ... I suspect that there is no way to add the extension.

+2
source

.putExtra, "Force Close". - :   mtUri = "mailto: someone@gmail.com? Subject = Some Subject & body = Some text &";   = (Intent.ACTION_SENDTO, Uri.parse(mtUri));  startActivity ();

, . "attachment = file:///...".

,

+1

Source: https://habr.com/ru/post/1766232/


All Articles