Skip to content

Instantly share code, notes, and snippets.

@kodeshpa
Created June 26, 2011 19:11
Show Gist options
  • Save kodeshpa/1047873 to your computer and use it in GitHub Desktop.
Save kodeshpa/1047873 to your computer and use it in GitHub Desktop.
/*
* Method to attach and send files from android application
*/
private void emailFiles(String filePath) {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
sendIntent.putExtra(Intent.EXTRA_TEXT, report);
if(!TextUtils.isEmpty(filePath)){
File fileIn = new File(filePath);
Uri u = Uri.fromFile(fileIn);
sendIntent.putExtra(Intent.EXTRA_STREAM, u);
}
String currentDateTimeString = DateFormat.getDateInstance().format(new Date());
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "MyEmail " + currentDateTimeString );
try{
startActivity(Intent.createChooser(sendIntent, "Select Destination"));
}catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(YouActivityName.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment