Skip to content

Instantly share code, notes, and snippets.

@laaptu
Created July 23, 2014 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laaptu/00a9bad05127963cdbd7 to your computer and use it in GitHub Desktop.
Save laaptu/00a9bad05127963cdbd7 to your computer and use it in GitHub Desktop.
Send email with attachment
Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Payment Information");
emailIntent.putExtra(Intent.EXTRA_TEXT, stringBuilder.toString());
emailIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { emailValue });
ArrayList<Uri> uris = new ArrayList<Uri>();
// convert from paths to Android friendly Parcelable Uri's
Uri uri = null;
if (params.containsKey(GeneralUtils.DESCRIPTION_IMAGE)) {
uri = getUriFromPath(params
.getString(GeneralUtils.DESCRIPTION_IMAGE));
if (uri != null)
uris.add(uri);
}
if (params.containsKey(GeneralUtils.SIGNATURE)) {
uri = getUriFromPath(params.getString(GeneralUtils.SIGNATURE));
if (uri != null)
uris.add(uri);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivityForResult(
Intent.createChooser(emailIntent, "Send mail using..."), 2);
private Uri getUriFromPath(String path) {
if (GeneralUtils.isFilePresent(path)) {
File file = new File(path);
return Uri.fromFile(file);
}
return null;
}
public static boolean isFilePresent(String filePath) {
if (isEmptyString(filePath))
return false;
File file = new File(filePath);
return file.exists();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment