I'm working on creating an app but I'm having a problem. After I've inserted some data in a file named "message.txt", I'm not able to send this file by e-mail because my smartphone says "impossible to send the attachment". How can I resolve this problem?
This is the code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String address = ...
byte[] messagetosend = ...
String filename = "message.txt";
File file = new File(getExternalFilesDir(null), filename);
FileOutputStream outputstream;
try {
outputstream = openFileOutput(filename,MODE_WORLD_READABLE);
outputstream.write(messagetosend);
outputstream.flush();
outputstream.getFD().sync();
outputstream.close();
} catch (Exception e1) {
e1.printStackTrace();
}
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{address});
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.setType("*/*");
startActivity(Intent.createChooser(sendIntent,"Send with..."));
}