I have looked at many codes online but all of them seem to run into a problem.
File is created and saved using the below function:
private static String filename = "eulerY.txt" ;
private void saveData() {
FileOutputStream fos_FILE_eulerY = null;
String message = "hello";
try {
fos_FILE_eulerY = openFileOutput(filename , MODE_PRIVATE);
fos_FILE_eulerY.write(message.getBytes());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos_FILE_eulerY != null) {
try {
fos_FILE_eulerY.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// export data
sendEmail ();
}
However, when running the below code to send the file, I keep running into the problem ClipData.Item.getUri
And as suggested using all the answer from this link "https://stackoverflow.com/questions/48117511/exposed-beyond-app-through-clipdata-item-geturi", when opening Gmail, it says "unable to attach file"
private void sendEmail (){
File filelocation = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), filename);
Uri path = Uri.fromFile(filelocation);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"asd@gmail.com"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, path);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
}
I would appreciate it if there is any way to send this file.