-3

I'm developing an android app in which i'll be generating an pdf file which i want to sent as an email. Following is the code for generating pdf file:

 public void createPDF(View view) {
        Document doc = new Document();
        String outPath = Environment.getExternalStorageDirectory()+"/mypdf.pdf";
        try {
            PdfWriter.getInstance(doc,new FileOutputStream(outPath));
            doc.open();
            doc.add(new Paragraph(edttxt1.getText().toString()));
            doc.add(new Paragraph(txt.getText().toString()));
            doc.close();
        } catch (DocumentException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

Help me to email this file by clicking a button.

Vishal G. Gohel
  • 1,008
  • 1
  • 16
  • 31
rambo
  • 11
  • 3

1 Answers1

-1

you can see more details here: How to send an email with a file attachment in Android

Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email@example.com"});
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "body text");
    File root = Environment.getExternalStorageDirectory();
    String pathToMyAttachedFile = "/mypdf.pdf";
    File file = new File(root, pathToMyAttachedFile);
    if (!file.exists() || !file.canRead()) {
    return;
    }
    Uri uri = Uri.fromFile(file);
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(emailIntent, "Pick an Email provider"));
Clapa Lucian
  • 590
  • 2
  • 7
  • 14