1

I am sending a file in email file. The file sent but its size remains 0kb and file looses all data. Is there any way to do the same and file remains with is original contents? I am using following code.

File f=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/SMSZip/a1.rar");

            Uri uri = Uri.fromFile(f);
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"abc77@gmail.com"});
            i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
            i.putExtra(Intent.EXTRA_TEXT   , "body of email");
            i.putExtra(Intent.EXTRA_STREAM, Uri.parse(f.getAbsolutePath()));

            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(getApplicationContext(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }
Jaydeepsinh Jadeja
  • 391
  • 2
  • 10
  • 20
  • i.putExtra(Intent.EXTRA_STREAM, Uri.parse(f.getAbsolutePath())); this should be i.putExtra(Intent.EXTRA_STREAM, uri); try this. – user370305 Feb 28 '12 at 08:28

2 Answers2

0

i've done for send 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:"));
pradip
  • 185
  • 1
  • 3
  • 11
0

From your code,

i.putExtra(Intent.EXTRA_STREAM, Uri.parse(f.getAbsolutePath())); 

this should be

i.putExtra(Intent.EXTRA_STREAM, uri); 

try this.

user370305
  • 108,599
  • 23
  • 164
  • 151
  • For more info look at [Trying to attach a file from SD Card to email](http://stackoverflow.com/questions/587917/trying-to-attach-a-file-from-sd-card-to-email) – user370305 Feb 28 '12 at 08:37