Take the 2-minute tour ×

I am trying to attach a PDF file called download.pdf to an email in my Android App. I am copying the file first to the SDCard and then attaching it the email.

I'm not if relevant, but I am testing on a galaxy tab device. The external storage path returns mnt/sdcard/

My code is as follows :

public void sendemail() throws IOException {


    String emailAddress[] = {""};

    File externalStorage = Environment.getExternalStorageDirectory();

    Uri uri = Uri.fromFile(new File(externalStorage.getAbsolutePath() + "/" + "download.pdf"));

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Text");
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(emailIntent, "Send email using:"));


public void CopyAssets() {
    AssetManager assetManager = getAssets();
    String[] files = null;
    try {
        files = assetManager.list("");
    } catch (IOException e) {
        Log.e("tag", e.getMessage());
    for(String filename : files) {
        InputStream in = null;
        OutputStream out = null;
        if (filename.equals("download.pdf")) {
        try {
          System.out.println("Filename is " + filename);
          in = assetManager.open(filename);
          File externalStorage = Environment.getExternalStorageDirectory();
          out = new FileOutputStream(externalStorage.getAbsolutePath() + "/" + filename);
          System.out.println("Loacation is" + out);
          copyFile(in, out);
          in = null;
          out = null;
        } catch(Exception e) {
            Log.e("tag", e.getMessage());
private void copyFile(InputStream in, OutputStream out) throws IOException {
    byte[] buffer = new byte[1024];
    int read;
    while((read = in.read(buffer)) != -1){
      out.write(buffer, 0, read);

The problem is that the file that is attached is 0 bytes in size. Can anyone spot what might be wrong ?


I can see that the file has been saved onto the device if I look in settings, therefore this must be a problem around how I am attaching the file to the email. In the error log I am seeing :

gMail Attachment URI: file:///mnt/sdcard/download.pdf
gMail type: application/pdf
gmail name: download.pdf
gmail size: 0


Wondering if this is a bug on the galaxy tab ? If I open the file via a pdf viewer (from my app) then try to attach to a gmail email, the size is again 0. Can anyone verify ?

Thank you.

share|improve this question
Does your app have permission to access the SD card? –  Tony the Pony May 21 '12 at 13:32
Yes - in manifest - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> –  GuybrushThreepwood May 21 '12 at 13:45
Did you check the pdf file size in your sdcard which was you copied using copyAssets() method. –  Praveen May 22 '12 at 10:15
Yep - and its the right size. –  GuybrushThreepwood May 22 '12 at 13:20
did you found a workaround for this issue? –  Pablo Jun 9 '12 at 18:42

3 Answers 3

If your download.pdf file exists in SDCard. So the problem should be get Uri from File. Try this, it works for me.

Uri uri = Uri.fromFile(new File("/sdcard/", "download.pdf"));
share|improve this answer
Doesn't help - isn't this essentially the same thing I have above ? –  GuybrushThreepwood May 21 '12 at 15:03
K, I try to help you, take a look in here trying-to-attach-a-file-from-sd-card-to-email. It may help you –  tai.tran2008 May 21 '12 at 15:14
Thanks, but I've already found that thread and nothing helps. –  GuybrushThreepwood May 21 '12 at 15:19

The same problem happens for me also. I've cleared that using some method from examples. I've already answered a question similar to your query. Maybe that can be helps you.

share|improve this answer
File externalStorage = Environment.getExternalStorageDirectory();    
String PDFpath = externalStorage.toString();
String pdfpath =path.replace("/mnt","");
Uri uri = Uri.parse(new File("file://" + pdfpath));
share|improve this answer

Your Answer


