By using following code, i am trying to attach multiple files to an E-Mail, but not getting attachments when using ArrayList.
public void sendImage() {
// TODO Auto-generated method stub
Intent i = new Intent(Intent.ACTION_SEND_MULTIPLE);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("message/rfc822");
i.setClassName("com.google.android.gm",
"com.google.android.gm.ComposeActivityGmail");
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "test#domain.tld" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT, "body of email");
ArrayList<Uri> uris = new ArrayList<Uri>();
String[] filePaths = new String[] {
"file:///sdcard/Custom/CapturedVideo.mp4",
"file:///sdcard/Custom/CapturedImage.jpg" };
for (String file : filePaths) {
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
i.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(i);
}
Note:- Earlier i was attaching single file to an EMail ! successfully !
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Custom/CapturedImage.jpg"));
try with full path like this
uris.add(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg")));
use this
Intent share = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
instead of
Intent share = new Intent(android.content.Intent.ACTION_SEND);
try this
Intent ei = new Intent(Intent.ACTION_SEND_MULTIPLE);
ei.setType("plain/text");
ei.putExtra(Intent.EXTRA_EMAIL, new String[] {"email id"});
ei.putExtra(Intent.EXTRA_SUBJECT, "That one works");
ArrayList<String> fileList = new ArrayList<String>();
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/qualifications.jpg");
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/certi/certificate.jpg");
fileList.add(Environment.getExternalStorageDirectory()+"/foldername/Aa.pdf");
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (int i=0;i<fileList.size();i++)
{
File fileIn = new File(fileList.get(i));
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
ei.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivityForResult(Intent.createChooser(ei, "Sending multiple attachment"), 12345);
Try with this one,
public void sendImage() {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("message/rfc822");
intent.setClassName("com.google.android.gm",
"com.google.android.gm.ComposeActivityGmail");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test#domain.tld" });
intent.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
intent.putExtra(Intent.EXTRA_TEXT, "body of email");
ArrayList<String> fileList = new ArrayList<String>();
fileList.add(Environment.getExternalStorageDirectory()+"/Custom/CapturedVideo.mp4");
fileList.add(Environment.getExternalStorageDirectory()+"/Custom/CapturedImage.jpg");
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (int i=0;i<fileList.size();i++)
{
File fileIn = new File(fileList.get(i));
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(intent);
}
Related
So in my current form of my app, I am able to send an email with a single image using the following:
private void dispatchSubmitBonusIntent() {
Intent sendEmailIntent = new Intent(Intent.ACTION_SEND);
sendEmailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendEmailIntent.setType("text/plain");
sendEmailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{submissionEmailAddress});
sendEmailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "2019_" + riderNumToH + "_" + bonusCategory.getText() +"_" + bonusState.getText() + "_" + bonusCity.getText() + "_" + bonusCode.getText());
sendEmailIntent.putExtra(Intent.EXTRA_TEXT, "Sent from aTOH App");
if (mainPhotoPath != null) {
sendEmailIntent.putExtra(android.content.Intent.EXTRA_STREAM, FileProvider.getUriForFile(captureBonus.this, "net.tommyc.android.tourofhonor", mainPhotoUri));
Log.v("MainImageFound", mainPhotoPath + "|" + mainPhotoUri);
if (secondaryPhotoPath != null) {
sendEmailIntent.putExtra(android.content.Intent.EXTRA_STREAM, FileProvider.getUriForFile(captureBonus.this, "net.tommyc.android.tourofhonor", secondaryPhotoUri));
Log.v("SecondaryImageFound", secondaryPhotoPath + "|" + secondaryPhotoUri);
} else {
Log.e("NoImageFound", "Image Not Found");
}
}
this.startActivity(Intent.createChooser(sendEmailIntent, "Sending email..."));
}
I am needing it to send up to two attachments, so I'm converting it over to an ACTION_SEND_MULTIPLE. I have the following code, but I'm not sure what to put inside the for loop for it to work.
public void sendEmail(Context context, String emailTo, String emailCC,
String subject, String emailText, List<String> filePaths)
{
//need to "send multiple" to get more than one attachment
final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{submissionEmailAddress});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "2019_" + riderNumToH + "_" + bonusCategory.getText() +"_" + bonusState.getText() + "_" + bonusCity.getText() + "_" + bonusCode.getText());
emailIntent.putExtra(Intent.EXTRA_TEXT, "Sent from aTOH App");
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(Intent.createChooser(emailIntent, "Sending email ..."));
}
What do I put in the for section so the it will grab the one or two images that need to be attached?
EDIT 1: I made some changes based on the answer I was given, but it still isn't working. I get an error that says android.os.FileUriExposedException: file:///storage/emulated/0/Pictures/Tour%20of%20Honor/2019_541_AK6_1.jpg exposed beyond app through ClipData.Item.getUri() (That file path is correct though).
public void dispatchSubmitBonusIntent() {
Log.e(TAG, "entering dispatchSubmitBonusIntent");
//need to "send multiple" to use more than one attachment
final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
// Set up the email parameters
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{submissionEmailAddress});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "2019_" + riderNumToH + "_" + bonusCategory.getText() +"_" + bonusState.getText() + "_" + bonusCity.getText() + "_" + bonusCode.getText());
emailIntent.putExtra(Intent.EXTRA_TEXT, "Sent via TOH App for Android");
// Get the attachments
Uri mainPhotoURI = FileProvider.getUriForFile(captureBonus.this, "net.tommyc.android.tourofhonor", mainPhotoUri);
Uri optPhotoURI = FileProvider.getUriForFile(captureBonus.this, "net.tommyc.android.tourofhonor", secondaryPhotoUri);
//has to be an ArrayList
ArrayList<Uri> uris = new ArrayList<Uri>();
String[] filePaths = new String[] {mainPhotoURI.toString(), optPhotoURI.toString()};
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
// Add the attachments to the email and trigger the email intent
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
this.startActivity(Intent.createChooser(emailIntent, "Sending email ..."));
}
Create one method for sending multiple attachments using an array
public boolean sendEmailIntentWithMultipleAttachments(Context context,
String[] emailTo, String[] emailCC, String[] emailBCC,
String subject, String emailBody, List filePaths) throws ActivityNotFoundException {
final Intent emailIntent =
new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("message/rfc822");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailTo);
emailIntent.putExtra(android.content.Intent.EXTRA_CC, emailCC);
emailIntent.putExtra(android.content.Intent.EXTRA_BCC, emailBCC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
ArrayList<String> extra_text = new ArrayList<String>();
extra_text.add("Hello This is multiple Email Text");
ei.putStringArrayListExtra(Intent.EXTRA_TEXT, extra_text);
if (filePaths != null) {
// has to be an ArrayList
ArrayList uris = new ArrayList();
// convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths) {
File fileIn = new File(file);
if (fileIn.exists()) {
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
}
emailIntent.putParcelableArrayListExtra
(Intent.EXTRA_STREAM, uris);
}
context.startActivity(Intent.createChooser(emailIntent, "Sent mail"));
return true;
}
Create an imageArray like this and set to intent putParcelableArrayListExtra
ArrayList<Uri> uris = new ArrayList<Uri>();
String[] filePaths = new String[] {"sdcard/sample.png", "sdcard/sample.png"};
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);
Its working fine in my app
I want share an album image from list url link.
Here is my code :
public void shareImg(ArrayList<String> arrUrl, String name) {
ArrayList<Uri> imageUris = new ArrayList<Uri>();
for(String path : arrUrl /* List of the files you want to send */) {
File file = new File(path);
Uri uri = Uri.fromFile(file);
imageUris.add(uri);
}
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, imageUris);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, "Share images to.."));
}
But it not run, what happend in here. please help me. Thank every one.
Try this code.
Here I parse images from bitmap to URI and put them to share intent
private void shareImages() {
ArrayList<Uri> uris = new ArrayList<>();
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
share.setType("image/jpeg");
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, "title");
values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
for(int i = 0; i < bitmaps.size(); i++) {
Uri uri = activity.getContentResolver().
insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
OutputStream outstream;
try {
outstream = activity.getContentResolver().openOutputStream(uri);
bitmaps.get(i).compress(Bitmap.CompressFormat.JPEG, 100, outstream);
outstream.close();
} catch (Exception e) {
System.err.println(e.toString());
}
uris.add(uri);
}
show.set(false);
share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
activity.startActivity(Intent.createChooser(share, "Share Image"));
}
Hope it helps :)
I am attaching a TEXT file to Email with code :
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",
"abc#gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Report");
emailIntent.putExtra(Intent.EXTRA_TEXT, prepareBodyMail());
File root = Environment.getExternalStorageDirectory();
File file = new File(root, "/MyFolder/report.txt");
Uri uri = Uri.fromFile(file);
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Pick an Email provider"));
This code works perfectly with Gmail, Email and other apps
But this is not attaching file with INBOX application by Google
Only Body and subject are coming without any attachment
I have reported this problem to Google Groups at Inbox Problem
Can anybody help what I am missing in code?
String fileLocation = Environment.getExternalStorageDirectory() + "/MyFolder/report.txt";
String to[] = {"abc#gmail.com"};
Intent intentEmail = new Intent(Intent.ACTION_SEND);
intentEmail.setType("vnd.android.cursor.dir/email");
intentEmail.putExtra(Intent.EXTRA_EMAIL, to);
intentEmail.putExtra(Intent.EXTRA_STREAM, fileLocation);
intentEmail.putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(intentEmail , "Pick an Email provider"));
Try this
Uri myUri = Uri.parse("file://" + path);
emailIntent.putExtra(Intent.EXTRA_STREAM, myUri);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"email#example.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "subject here");
intent.putExtra(Intent.EXTRA_TEXT, "body text");
File root = Environment.getExternalStorageDirectory();
File file = new File(root, xmlFilename);
if (!file.exists() || !file.canRead()) {
Toast.makeText(this, "Attachment Error", Toast.LENGTH_SHORT).show();
finish();
return;
}
Uri uri = Uri.fromFile("file://" + file);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Send email..."));
public void sendMailWithIntent(String emailTo,
String subject, String emailText, List<String> filePaths) {
try {
//need to "send multiple" to get more than one attachment
final Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
Util.extractEmails(emailTo));
// emailIntent.putExtra(android.content.Intent.EXTRA_CC,
// new String[]{emailCC});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, emailText);
ArrayList<Uri> uris = new ArrayList<Uri>();
//has to be an ArrayList
if (filePaths != null) {
//convert from paths to Android friendly Parcelable Uri's
for (String file : filePaths) {
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
Intent chooser = Intent.createChooser(emailIntent, "Send mail...");
activity.startActivityForResult(chooser, 1);
} catch (Exception e) {
new ShowToast(context, e.getMessage());
}
}
Call method
List<String> list = new ArrayList<>();
list.add(TO_ATTACH_ONE);
list.add(TO_ATTACH_TWO);
sendMailWithIntent(toAddresses, subject, body, list);
It looks like that ACTION_SENDTO doesn't support attachments officially. It works only for Gmail and default email client because they use "undocumented" feature. The only way I found to send emails with attachments is to use ACTION_SEND instead.
My solution:
public class EmailSender {
private static final String INTENT_DATA_SCHEME_EMAIL = "mailto:";
private static final String FILE_PROVIDER_AUTHORIZER = "com.smartinhalerlive.app.fileprovider";
private String subject;
private String body;
private File attachment;
public EmailSender(String subject, String body, File attachment) {
this.subject = subject;
this.body = body;
this.attachment = attachment;
}
public void sendEmail(Context context, EmailSenderListener listener) {
List<ResolveInfo> emailClients = getEmailClients(context);
if (null != emailClients) {
ResolveInfo defaultEmailClient = getDefaultEmailClient(emailClients);
if (null != defaultEmailClient) {
sendEmailUsingSelectedEmailClient(context, defaultEmailClient, listener);
} else {
showSelectEmailClientsDialog(context, emailClients, listener);
}
}
}
private void showSelectEmailClientsDialog(Context context,
List<ResolveInfo> emailClients,
EmailSenderListener listener) {
String[] emailClientNames = getEmailClientNames(context, emailClients);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.email_dialog_title);
builder.setItems(emailClientNames, (dialog, which) -> {
sendEmailUsingSelectedEmailClient(context, emailClients.get(which), listener);
}
);
builder.create().show();
}
#NonNull
private static String[] getEmailClientNames(Context context, List<ResolveInfo> emailClients) {
PackageManager packageManager = context.getPackageManager();
String[] emailClientNames = new String[emailClients.size()];
for (int i = 0; i < emailClients.size(); i++) {
emailClientNames[i] = emailClients.get(i).activityInfo.applicationInfo.loadLabel(packageManager).toString();
}
return emailClientNames;
}
#Nullable
private static ResolveInfo getDefaultEmailClient(List<ResolveInfo> emailClients) {
ResolveInfo defaultEmailClient = null;
if (emailClients.size() == 1) {
defaultEmailClient = emailClients.get(0);
} else {
for (ResolveInfo emailClient : emailClients) {
if (emailClient.isDefault) {
defaultEmailClient = emailClient;
break;
}
}
}
return defaultEmailClient;
}
private static List<ResolveInfo> getEmailClients(Context context) {
PackageManager pm = context.getPackageManager();
Intent emailDummyIntent = getEmptyEmailIntent();
return pm.queryIntentActivities(emailDummyIntent, 0);
}
public static Intent getEmptyEmailIntent() {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(INTENT_DATA_SCHEME_EMAIL));
return emailIntent;
}
private static void grantReadPermissionForAttachmentUri(Context context,
Intent emailIntent,
Uri attachmentUri) {
if (emailIntent == null || attachmentUri == null) {
return;
}
context.grantUriPermission(emailIntent.getComponent().getPackageName(),
attachmentUri,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
private void sendEmailUsingSelectedEmailClient(Context context,
ResolveInfo emailClient,
EmailSenderListener listener) {
try {
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, null != subject ? subject : "");
emailIntent.putExtra(Intent.EXTRA_TEXT, null != body ? body : "");
emailIntent.setComponent(new ComponentName(emailClient.activityInfo.packageName, emailClient.activityInfo.name));
addAttachment(context, attachment, emailIntent);
listener.onEmailIntentReady(emailIntent);
} catch (Exception ex) {
Timber.e("Error sending email", ex);
}
}
private static void addAttachment(Context context, File attachment, Intent emailIntent) {
if (attachment != null) {
Uri contentUri = FileProvider.getUriForFile(context, FILE_PROVIDER_AUTHORIZER, attachment);
grantReadPermissionForAttachmentUri(context, emailIntent, contentUri);
emailIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
}
}
public interface EmailSenderListener {
void onEmailIntentReady(Intent emailIntent);
}
}
I'm new here on stackoverflow. I have a little problem with my Android app, expecially with an ImageView that triggers an event on tap. This event opens an email client with some pre-written text and it should attach the image of the Image. I already know that the image should be converted into a bitmap before, then compressed and send it to the email client, but unfortunatly I'm not an Android/Java expert so I can't find how to do that. This is the code of the email method:
new code below
Where I have to replace "String imageURI = null;" with what the email needs as image. Thank you all!
EDIT:
I managed to edit my code to this, that gives no errors:
public void sendMail(ImageView image){
Intent i = new Intent(Intent.ACTION_SEND);
int imageURI = R.drawable.img1;
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"destinatario#globelife.biz"});
i.putExtra(Intent.EXTRA_SUBJECT, "Oggetto");
i.putExtra(Intent.EXTRA_TEXT , "Globelife");
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://"+getPackageName()+"/"+imageURI));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Test01Activity.this, "Non sono presenti app per l'invio di e-mails.", Toast.LENGTH_SHORT).show();
}
}
But I need to change "int imageURI = R.drawable.img1;" to "int imageURI = ImageView.src;" or something like that
try this
ImageView iv = (ImageView) findViewById(R.id.splashImageView);
Drawable d =iv.getBackground();
BitmapDrawable bitDw = ((BitmapDrawable) d);
Bitmap bitmap = bitDw.getBitmap();
File mFile = savebitmap(bitmap);
and then
Uri u = null;
u = Uri.fromFile(mFile);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Hello...");
// + "\n\r" + "\n\r" +
// feed.get(Selectedposition).DETAIL_OBJECT.IMG_URL
emailIntent.putExtra(Intent.EXTRA_TEXT, "Your tsxt here");
emailIntent.putExtra(Intent.EXTRA_STREAM, u);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
and savebitmap method
private File savebitmap(Bitmap bmp) {
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
OutputStream outStream = null;
File file = new File(extStorageDirectory, temp + ".png");
if (file.exists()) {
file.delete();
file = new File(extStorageDirectory, temp + ".png");
}
try {
outStream = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
} catch (Exception e) {
e.printStackTrace();
return null;
}
return file;
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/Pictures/
image.jpg"));
startActivity(i);
Intent intent=new Intent(Intent.ACTION_SEND);
String[] recipients={"destinatario#domain.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.putExtra(Intent.EXTRA_SUBJECT, "Oggetto");
intent.putExtra(Intent.EXTRA_TEXT , "Testo");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse(“file///sdcard/Images/your_image.jpg”));//or you can pass the path of your image
startActivity(Intent.createChooser(intent, "Send mail"));
//re move the String imageURI=null;
public void sendMail(ImageView image){
Intent i = new Intent(Intent.ACTION_SEND);
Uri pngImageUri = Uri.parse(image);
i.setType("image/png");//change here with image/png
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"destinatario#domain.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "Oggetto");
i.putExtra(Intent.EXTRA_TEXT , "Testo");
i.putExtra(Intent.EXTRA_STREAM, pngImageUri);
I would like to send email via
startActivity(Intent.createChooser(new Intent(android.content.Intent.ACTION_SEND)))
I know that to attach file to email I need
intentEmail.putExtra(android.content.Intent.EXTRA_STREAM, <Uri of file>)
but I need to attach several files. How can I do this?
This should work to send multiple attachments
public static void sendEmail(Context context, String emailTo, String emailCC,
String subject, String message, List<String> filePaths)
{
//send email with multiple attachments
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{emailTo});
emailIntent.putExtra(android.content.Intent.EXTRA_CC,
new String[]{emailCC});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
message);
ArrayList<Uri> uris = new ArrayList<Uri>();
//convert from paths to Uri's
for (String file : filePaths)
{
File fileIn = new File(file);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
context.startActivity(emailIntent);
}