1

I am sending a pdf file in email attachment, attachment is going successfully in email and it is showing me in email as attachment, but when i download this pdf it having no content i.e. it's size is zero byte. Am I missing some permission? or Any solution regarding this?

Here is my code

private void emailSend(String emailString, String subject, String pdfPath){

        String[] email = { emailString };
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

        emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"MY body");
        emailIntent.setType("application/pdf");
        emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));

        startActivity(Intent.createChooser(emailIntent, "Send mail..."));
    }
Himanshu
  • 1,066
  • 6
  • 19
  • 44

2 Answers2

2

Finally i got the solution to my problem from this post.

I use

emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(pdfPath)));

instead of

emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));

it resolved my issue.

Thanks

Community
  • 1
  • 1
Himanshu
  • 1,066
  • 6
  • 19
  • 44
1

I've done this for sending any file from SD card with mail attachment...

Intent sendEmail= new Intent(Intent.ACTION_SEND);
       sendEmail.setType("rar/image");
       sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new        
         File("/mnt/sdcard/download/abc.rar")));
         startActivity(Intent.createChooser(sendEmail, "Email:"));
Community
  • 1
  • 1
pradip
  • 185
  • 1
  • 3
  • 11