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);
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_READABLEflag. This is needed for the other application to be able to open the PDF.Then use
Uri.fromFileto get an Android URI to your file (you have this in commented code).Note that
MODE_WORLD_WRITEABLEis 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 aContentProviderand use acontent: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).