How do you attach a file that is in the memory for example a string, with a file extension of .txt etc. I have tried storing the string the internel memory and then attaching it and I can't get it to work either though I would much prefer I solution to my first problem.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text");
try {
FileOutputStream fos = openFileOutput("data.enw", Context.MODE_PRIVATE);
fos.write(export_text.getBytes());
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
i.putExtra(Intent.EXTRA_STREAM, Uri.parse(new File("data.enw").toString()));
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"MyEmail"});
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Attachment");
i.putExtra(android.content.Intent.EXTRA_TEXT, "Import the attachment");
startActivity(Intent.createChooser(i, "E-mail"));
[Edit] The code below works however it requires an SD Card. Is there a better way of doing it.
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("plain/text");
File data = null;
try {
data = File.createTempFile("data", ".enw");
FileOutputStream out = new FileOutputStream(data);
out.write(export_text.getBytes());
out.close();
} catch (IOException e) {
e.printStackTrace();
}
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(data));
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"MyEmail"});
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Attachment");
i.putExtra(android.content.Intent.EXTRA_TEXT, "Import the attachment");
startActivity(Intent.createChooser(i, "E-mail"));