0

i have to make an application in which first i have to create a text file from the data user has entered in the UI and then send the text file as an attachment in an email. For this i will have to write data to the external directory and then pass the URI to the Intent so that the email client in the phone can read it.

i am not sure how would i:

  1. write data to the external storage.

2.Pass the URI of the file created to the Intent so that i can attach it to the email.

I have seen several examples of how to send email attachments.. but none fit my requirements hence as a last resort i am posting this question.

thank you in advance.

user743883
  • 107
  • 1
  • 7
  • Please try to develop your own solution based on the answers to the numerous existing questions on this topic and the developer docs, and then post a question of your own if you get stuck at a specific point where something isn't working as expected. – Chris Stratton May 21 '11 at 06:28
  • Could you give those links, and explain what about them doesn't fit your requirements? – Jodes May 21 '11 at 06:32

1 Answers1

1

Both questions have been answered here many times.

External storage:

Attach a file to an email:

I honestly cannot figure out what is so specific about your requirements. It looks like a pretty standard task to me...

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • the Gmail or any other email client will not be able to access if i store the file inside my application....i have to store it in public..somewhere in the external storage....so that other applications can access my data. – user743883 May 21 '11 at 06:52
  • @user that is correct. I forgot about that detail :/ Anyway, what is the part you're stuck in? – Aleadam May 21 '11 at 06:56
  • first there are several public directories...like Environment.DOWNLOADS, MUSIC..where should i put my file? Also once i have put it in that directory how do pass it to the Intent which i am calling to send email? – user743883 May 21 '11 at 07:10
  • You can create any folder you want in there. None of the standard ones seem suitable for a text file, so you can create a folder with your app name and put it inside it. If you're going to delete the file as soon as it is sent, then a tmp folder would not be a bad idea. If you're making a Froyo app, check this option: http://developer.android.com/reference/android/content/Context.html#getExternalCacheDir%28%29 – Aleadam May 21 '11 at 07:20
  • For the second question, the two links I posted for emails show how to pass the file path to the email intent. – Aleadam May 21 '11 at 07:21