3

I am sending a mail by using below code and i need to send a .text file also using gmail only. How can i do it? Please can any one help me?

Intent send = new Intent(Intent.ACTION_SENDTO);
            String uriText = "mailto:" + Uri.encode("") + 
                      "?subject=" + Uri.encode("Sample Text") + 
                      "&body=" + Uri.encode("Hi");
            Uri uri = Uri.parse(uriText);

            send.setData(uri);
            startActivity(Intent.createChooser(send, "Send mail..."));

Thanking in Advance.

suman
  • 75
  • 3
  • 8
  • Look at http://stackoverflow.com/questions/5762073/problem-attaching-internal-file-to-gmail-in-my-android-app and http://stackoverflow.com/questions/5843834/attaching-a-file-from-secure-storage-in-gmail-from-my-app – NeeL May 16 '13 at 07:13

1 Answers1

6
File sd = Environment.getExternalStorageDirectory();
File fileDir= new File(sd, "dir_path");
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileDir.getAbsolutePath() + "/"
                                    + FILE_TXT
 startActivity(Intent.createChooser(email , "Email: Text File"));
Tarun
  • 13,727
  • 8
  • 42
  • 57
  • Thanks for your replay.Here ,what is FILE_TEXT. – suman May 16 '13 at 08:18
  • i sent sample.text file, but i didn't get any attachment and i am using email.setType("text/plain"); – suman May 16 '13 at 08:24
  • my code is:File sd = Environment.getExternalStorageDirectory(); File fileDir= new File(sd, "dir_path"); Intent email = new Intent(Intent.ACTION_SEND); email.setType("text/plain"); email.putExtra(Intent.EXTRA_STREAM, Uri.parse(fileDir.getAbsolutePath() + "/"+ "sample.text")); startActivity(Intent.createChooser(email , "Email: Text File")); – suman May 16 '13 at 08:25
  • Check File fileDir= new File(sd, "dir_path"); it should point to your actual directory path where the file exists. – Tarun May 16 '13 at 09:36