Skip to content

Instantly share code, notes, and snippets.

@paour
Created February 27, 2014 12:30
Show Gist options
  • Save paour/9249178 to your computer and use it in GitHub Desktop.
Save paour/9249178 to your computer and use it in GitHub Desktop.
Easy send attachment via email
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(sb.toString());
bw.close();
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "MyTrails state dump");
sendIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"support@frogsparks.com"});
sendIntent.putExtra(Intent.EXTRA_TEXT, "See attachment");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + file.getAbsolutePath()));
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Send state via email"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment