I have an Android application that saves a text file directly on the phone in the application installation directory. I need to allow the user to create a new email by attaching this saved text file. When I start the intention to send email, everything displays correctly in Gmail, but the attachment is not sent. All my attempts seem to be related only to attaching the image file from the SD card. Below is the code I used. Please let me know if I did something wrong.
File myFile = new File(getFilesDir() + "/" + "someFile.txt");
FileOutputStream stream = null;
if( file != null )
{
steam = openFileOutput("someFile.txt", Context.MODE_WORLD_READABLE);
stream.write(some_data);
Uri uri = Uri.fromFile(myFile);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
sendIntent.putExtra(Intent.EXTRA_TEXT, email_text);
sendIntent.putExtra(Intent.EXTRA_STREAM, uri);
file.close();
startActivity(Intent.createChooser(sendIntent, "Email:"));
}
I also tried sendIntent.setType ("application / octet-stream"); but that did not change the situation. I do not understand why the file is not attached or sent.
Any ideas?