Before anything else, I have actually read through several threads regarding sending attachments on Android. That said, I haven't found a solution to my problem.
My app is relatively simple, user types numbers, they get saved to "values.csv" using openFileOutput(filename, Context.MODE_APPEND);.
Now, here's the code I'm using to attach the file to an email and send (I got it from one of the other file threads.)
private void sendEmail(String email) {
File file = getFileStreamPath(filename);
Uri path = Uri.fromFile(file);
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("application/octet-stream");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
String to[] = { email };
intent.putExtra(Intent.EXTRA_EMAIL, to);
intent.putExtra(Intent.EXTRA_TEXT, "Testing...");
intent.putExtra(Intent.EXTRA_STREAM, path);
startActivityForResult(Intent.createChooser(intent, "Send mail..."),
1222);
}
This opens my email client, which does everything right except attach the file, showing me a toast notification saying "file doesn't exist."
Am I missing something? I've already added the permissions for reading and writing to external storage, by the way.
Any and all help would be much appreciated.
EDIT: I can use the File Explorer module in DDMS and navigate to /data/data/com.example.myapp/files/, where my values.csv is located, and copy it to my computer, so the file DOES exist. Must be a problem with my code.