Here is little sample how to send email (send intent to Mail app) with text file as attachment.

Screenshot:

2014-12-02 14.48.00

 

And here is source code of main feature:

I make the text file with sample text before sending. This need to make this sample works.

The full MainActivity.java is:

Don’t forget add permissions in the

 

Full source code you can fork from github

Download it from github

1 Comment

SUKHVIR SINGH · 14 September, 2017 at 11:51

sir , I try on this code but error while run on mobile through android studio error is ” permission is denied for attachment ”
if your code use “file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), FILENAME);” then IOException error (“Unable create temp file. Check logcat for stackTrace”)

if this code change with (file = new File(getFilesDir(),FILENAME);) then file save no IOException error and click on gmail then display error (” permission is denied for attachment “)

note:- my mobile redme note 3 and no sd card facility in it
Please any other solution to solve this problem

thanks:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.