Created
July 23, 2014 11:07
-
-
Save laaptu/00a9bad05127963cdbd7 to your computer and use it in GitHub Desktop.
Send email with attachment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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