0

I have to open my application e-mail (G-mail) and it must be attached to some pdfs

the pdf are located in a folder created by the application. the folder is not created on sdcard.

My tablet does not have sdcard. My tablet does not have sdcard. My tablet does not have sdcard.

how to send these pdfs for email?

if(android.os.Environment.getDataDirectory().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir=new File(android.os.Environment.getDataDirectory(),"MyAPP");



//String FILENAME = "testejan1.pdf";
//String string = "hello world!";



//File file = new File (Environment.getDataDirectory().getPath(), "/MyAPP/"+"testejan1.pdf");
//Uri path = Uri.fromFile(file);

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("application/pdf");
//shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "flip_novidade@hotmail.com" });
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Material de apoio do mês de " + mesclicado);
shareIntent.putExtra(Intent.EXTRA_TEXT, "Você esta recebendo um super material de visitação médica");
//shareIntent.setDataAndType(path, "application/pdf"); 
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///MyAPP/"+"testejan1.pdf"));
//shareIntent.setType("file/*");
startActivity(shareIntent);
Flip_novidade
  • 11
  • 1
  • 8

2 Answers2

0
i.setType("application/pdf");
 i.putExtra(Intent.EXTRA_STREAM, Uri.parse("pdf path"));
Kamal
  • 1,415
  • 13
  • 24
0

Most of your code looks right. Two things:

When you create the PDF file in your app's local filesystem, you need to create it with the MODE_WORLD_READABLE flag. This is needed for the other application to be able to open the PDF.

Then use Uri.fromFile to get an Android URI to your file (you have this in commented code).

Note that MODE_WORLD_WRITEABLE is considered a poor security practice, because ANY app on the device will be able to access your PDF file. A better solution would be to create a ContentProvider and use a content: URI to serve the PDF data to the external application. This gives you control over whether to permit or deny access for any individual load of the PDF file (but it's a bit more work).

Barend
  • 17,296
  • 2
  • 61
  • 80
  • One more thing: when you use Action.SHARE and PDF files, you'll run into [an app crash when Adobe Reader is installed](http://stackoverflow.com/q/10319928/49489). In the app I'm working on, we ended up building our own, custom Activity Chooser to work around this. – Barend Jan 16 '13 at 13:52
  • thank you very much for the detailed explanation. perfect. Had some examples to download the pdf (MODE_WORLD_WRITEABLE). And some examples using ContentProvider with pds external application. – Flip_novidade Jan 16 '13 at 14:06