I am making an app that makes a file and then I want to email it to myself. The Program just keeps saying: "couldn't attach file" after I choose the email manager. I think I may have the wrong file directory written, but I don't know what the correct one is if it isn't what I already have.
Here is the Email button code
btnEmailForm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String filelocation="data/data/CyberEye/files/form.txt"; // I think the problem is here
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent .setType("vnd.android.cursor.dir/email");
String to[] = {"myemail@place.edu"};
emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
// the attachment
emailIntent .putExtra(Intent.EXTRA_STREAM, filelocation);
// the mail subject
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "AppName");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
}
});
Here is the Code for my file saving
btnSaveForm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textEventName[0] = editEventName.getText().toString();
try {
FileOutputStream fou = openFileOutput("form.txt", MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fou);
try {
osw.write(String.valueOf(textEventName));
osw.flush();
osw.close();
Toast.makeText(getBaseContext(), "Data saved", Toast.LENGTH_LONG).show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});