how to send image via email in android? - android

I am developing an application in which i have to send an image via email, I tried with
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "xyz#gmal.com");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "message");
emailIntent.setType("image/png");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.a));
emailIntent.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailIntent);
but its giving me as gmail has stopped unfortunately.How can I send an image via email,
Thanks in advance.

Get the image storage path by using the file,
File img = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/", imagename+".png");
Convert that file path in to Uri
Uri imageuri = Uri.fromFile(img);
Send the image via email using
Intent send_img = new Intent(Intent.ACTION_SEND);
send_img.putExtra(Intent.EXTRA_EMAIL, "xyz#gmal.com");
send_img.putExtra(Intent.EXTRA_SUBJECT, "email_subject");
send_img.putExtra(Intent.EXTRA_STREAM, imageuri);
send_img.putExtra(Intent.EXTRA_TEXT, "message");
send_img.setType("text/plain");
send_img.setType("image/png");
startActivity(Intent.createChooser(send_img, "Send Email..."));

Related

Send email with attachment in Android. Works on Gmail but not on Outlook

So from my Android app I can send emails with attachment on Gmail. On outlook looks like it is attaching the file (.txt), but when I open the mail there is no attached file.
This is my code:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
Uri uriFileToShare = Uri.fromFile(file);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, file.getName());
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, uriFileToShare);
this.startActivityForResult(Intent.createChooser(emailIntent, activity.getString(R.string.send)+" "+file.getName()+" "+activity.getString(R.string.by_email)),code);
I have tried different solutions but no result.
The file of course exists and is not empty. As I said, on Gmail is correctly attached.
Any idea?
This code worked for me on outlook file attachment.
public static void emailLog(Context context) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/html");
String filePath = fileDir + "/" + fileName;
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
File recordingFile = new File(filePath);
Uri fileUri = Uri.fromFile(recordingFile);
emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
context.startActivity(Intent.createChooser(emailIntent, "Some text..."));
}

How to attach an image from SD Card to an email?

I am trying to attach an image from SD Card to an email (from my app to Gmail app).
Every time I try, I select Gmail app and it closes, it doesn't attach the file.
Let's say the image path is: /sdcard/DCIM/Snapseed/Snapseed4.jpg. This is the code I am using to send the email:
Intent emailintent2 = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailintent2.setType("image/*");
emailintent2.putExtra(Intent.EXTRA_EMAIL, emailaddress2);
emailintent2.putExtra(Intent.EXTRA_SUBJECT, CorAsunto);
emailintent2.putExtra(Intent.EXTRA_TEXT, message2);
Uri uris = Uri.fromFile(new File(Environment.getExternalStorageDirectory()
+ "/DCIM/Snapseed/Snapseed4.jpg"));
emailintent2.putExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailintent2);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("SDCARD IMAGE PATH"));
startActivity(Intent.createChooser(emailIntent,"Share image using"));

How to send image file in the body of the email

I know this question is already ask in the stack overflow, and I looked around them but don't get any clue. Actually I have written code for sending an image file as an attachment to my mail and its working fine. The code I used for sending an image file as an attachment is shown below. Can anyone tell me what are the changes I need to do to send the image file in the body of mail? Any clue will be helpful.
Code for sending the image as an attached file
Uri imageUri = Uri.parse("content://" + CachedFileProvider.AUTHORITY + "/" + fileNameArray.get(position));
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/png");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(i, "Send email"));
only work in device not in android emulator..
http://blogingtutorials.blogspot.com/2010/12/send-email-with-attached-file-in.html
Try using the following intent:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]
{"me#gmail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"Test Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
"go on read the emails");
Log.v(getClass().getSimpleName(), "sPhotoUri=" + Uri.parse("file:/"+ sPhotoFileName));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Android email send without attachment

I have to following problem:
I want to send an email with an image attached to it.
I wrote this code:
File file = context.getDir("Files", context.MODE_WORLD_WRITEABLE);
File image = new File(file, "image.jpg");
Uri U = Uri.fromFile(image);
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("image/jpg");
i.putExtra(Intent.EXTRA_STREAM, U);
context.startActivity(Intent.createChooser(i, "Email:"));
The email is sent but there is no attachment.
Does anybody have any idea why the email is sent without the attachment?
EDIT
I have found the answer to my question. Because the image was stored on the internal storage, it did not have enough rights so it could not be sent via email. I've moved my image to externalStorage and now it's working :)
Thanks,
Ark
String smsBody = "Body of the Content";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] { "" });
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject of the Mail");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, smsBody);
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile("mnt/sdCard/SampleImageFloder/TestImage.png"));
emailIntent.setType("vnd.android.cursor.dir/email");
activity.startActivity(Intent.createChooser(emailIntent,"Email:"));
Try this one -
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{"email"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Test");
//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(emailIntent);
Just see my Existing Answer also

Email with attachment

i am trying to send an email with an attachment using intent.
the file is a pdf stored in the raw folder. it is less than 200k.
but it shows file too large to attach. Y?
help me pls..
Intent in = new Intent(Intent.ACTION_SEND);
in.setType("application/pdf");
in.putExtra(Intent.EXTRA_EMAIL,new String[]{email.getText().toString()});
in.putExtra(Intent.EXTRA_SUBJECT, "Android Development Course");
Uri uri = Uri.parse("android.resource://deepak.android.samples/raw/android");
in.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(Intent.createChooser(in, "Sending email.."));
use this method
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{"emailaddress"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Body");
String rawFolderPath = "android.resource://" + getPackageName()
+ "/" + R.raw.shortcuts;
// Here my file name is shortcuts.pdf which i have stored in /res/raw folder
Uri emailUri = Uri.parse(rawFolderPath );
emailIntent.putExtra(Intent.EXTRA_STREAM, emailUri);
emailIntent.setType("application/pdf");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Categories

Resources