You sort of can, but it's ugly and inelegant. I'll work on smoothing this out.
The main problem: After the email is sent you end up at a black screen with nothing but your app title at the top.
I'll do a 'hit enter to continue' or something if I have to.
Anyway: First snippet from main class writes the report to sdcard, then calls the activity that will send email.
WriteReportToStorage();
Intent Emailreport = new Intent(bvsactivity.this, Emailreport.class);
startActivityForResult(Emailreport,emailreport_ran);
Next, over in the emailreport class we do the standard email+attachment sending code:
public class Emailreport extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Intent email = new Intent(android.content.Intent.ACTION_SEND);
email.setType("text/html
");
email.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
email.putExtra(android.content.Intent.EXTRA_TEXT, "body");
email.putExtra(android.content.Intent.EXTRA_STREAM, Uri.parse("file:/" + Environment.getExternalStorageDirectory() + "//Report.html"));
startActivity(Intent.createChooser(email, "Email:"));
}
Lastly, back in your 'main' class, the onactivityresult that deletes the sdcard file:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// Actions based on which menu item we chose.
if (requestCode == emailreport_ran) {boolean deleted = reportfile.delete(); emailreport_ran = 1;}
}
}