Sending an email with an attachment from an application

泪湿孤枕 提交于 2019-12-02 07:25:42
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:"));

need the correct path for your file, if on SD card then...

sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse 
("file://"+Environment.getExternalStorageDirectory()+getString(R.string.csv_title)"));

Look here for addition information on setting the appropriate file path

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

GMail app accepts file:// Uris only if they are on the sdcard... and on an android 1.6 device I had even an issue with it accepting only file://sdcard/* Uris whereas the real external storage of this specific device is on another path.

Anyway, I have a real better behavior with attachments since I provide them through a ContentProvider.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!