Issue with uploading an image email attachment for Android - android

For one of my projects, I'm trying to simply attach an image to an email and send it.
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("image/jpg");
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.putExtra(Intent.EXTRA_SUBJECT,
"Image attached.");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(filePath));
emailIntent.setType("text/plain");
startActivity(Intent.createChooser(emailIntent,
"Send email using.."));
My variable "filePath" is the absolute file path of an image found on the external storage of my device. It's in the form of "/mnt/sdcard/....." The path to my image is definitely correct because I am successfully loading photos into other image views.
This intent also works fine, and is able to bring me to a screen to select an application to use to send my image. HOWEVER, in the actual email, I can see that my image has been attached (the file path name is 100% correct), but the image itself does not get attached.
Does anyone have an idea as to what might be the cause to this problem?

Try this:
File fileToAttach = new File(filePath, filename);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileToAttach));

Also getting the same problem
Code:
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..."));
From adb logcat:
V/DumbDumpersMain( 3972): sPhotoUri=file://sdcard/DumbDumpers/DumbDumper.jpg
I/ActivityManager( 56): Starting activity: Intent { action=android.intent.action.CHOOSER comp={android/com.android.internal.app.ChooserActivity} (has extras) }
I/ActivityManager( 56): Starting activity: Intent { action=android.intent.action.SEND type=jpeg/image flags=0x3000000 comp={com.google.android.gm/com.google.android.gm.ComposeActivityGmail} (has extras) }
I/ActivityManager( 56): Starting activity: Intent { action=android.intent.action.SEND type=jpeg/image flags=0x2800000 comp={com.google.android.gm/com.google.android.gm.ComposeActivity} (has extras) }
D/gmail-ls( 120): MailProvider.query: content://gmail-ls/labels/me#gmail.com(null, null)
D/Gmail ( 2507): URI FOUND:file://sdcard/DumbDumpers/DumbDumper.jpg
Looks like the email provider is attaching a 0 length file. When I check the filesystem the file is there and correct. The code which creates the image file is well finished prior to the attempt to email it.
Anyone fixed this without magic reboots (I've already tried that)?
Update
Path for me should have been
file:///sdcard/DumbDumpers/DumbDumper.jpg
you need the extra / as this points to the root directory, i.e.:
file:// + /sdcard/DumbDumpers/DumbDumper.jpg
combined as
file:///sdcard/DumbDumpers/DumbDumper.jpg
In the above snippet you need:
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));
I hope this helps. It took me ages to debug.

Try out this way:
File pngDir = new File(Environment.getExternalStorageDirectory(),"DCIM/Camera");
File pngfile = new File(pngDir, "<ImageName>");
Uri pngUri = Uri.fromFile(pngfile);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/*");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"<Email>");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"<Subject>");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"<Message>");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,pngUri);
emailIntent.setType("image/png");
startActivity(Intent.createChooser(emailIntent, "Send mail..."));

Try this code
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("message/rfc822");
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Video");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+path));
sendIntent.putExtra(Intent.EXTRA_TEXT, "Enjoy the Video");
startActivity(Intent.createChooser(sendIntent, "Email:"))

Related

Sending mail with attachment in android

I am trying to send a with attachment where the attachment file could be any type of file(like txt,image,pdf etc) from a sd card.
I used these
String filelocation="file:/"+attachment_file_path1.getText().toString();
Intent emailIntent = new Intent(Intent.ACTION_SEND);
// set the type to 'email'
emailIntent.setType("text/plain");
String to[] = {"destination#yahoo.com"};
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "bodyyyyyyyyy");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(filelocation));
emailIntent .putExtra(Intent.EXTRA_SUBJECT, "my mail");
startActivity(Intent.createChooser(emailIntent , "Send email..."));
N:B: if i print the attachment_file_path1.getText().toString() it shows like "/storage/sdcard0/myfolder/my.txt"
my email is sent to the destination but my attachment is not sent.
How can i solve the problem??
Change your emailIntent.setType(text/plain) to emailIntent.setType("*/*") for allowing to send any file type.
Path format is :
file:///sdcard/DumbDumpers/DumbDumper.jpg
you need the extra / as this points to the root directory, i.e.:
file:// + /sdcard/DumbDumpers/DumbDumper.jpg
combined as
file:///sdcard/DumbDumpers/DumbDumper.jpg
In the above snippet you need:
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+ sPhotoFileName));

Email Attachment images cant Send

Written a code for send an email along attachment. Once I sent this email it added a garbage value in attachment.
Attached part was encoded in different format.
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/html");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {"user_one#example.com", "user_two#example.com" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + sPhotoFileName));
i.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(mailBody));
startActivity(Intent.createChooser(i, "Send mail..."));
Expected:
It should a attached images files other than encoded string.
Any help would highly appreciate .
Thanks in advance.
File jpegfile = new File(imageDir, "yourfilename.jpeg");
Uri jpegurl = Uri.fromFile(jpegfile);
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/jpeg"); //
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "mailid#domain.com" });
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Mail Subject");
intent.putExtra(android.content.Intent.EXTRA_CC, new String[] { "mailid#domain.com" });
intent.putExtra(Intent.EXTRA_TEXT, "Mail body text");
intent.putExtra(Intent.EXTRA_STREAM, jpegurl);
You need to set your intent type to handle images properly, assuming it is a png, as follows.
Intent emailIntent = new Intent(Intent.ACTION_SEND, Uri.fromFile(temp));
emailIntent.setType("image/png");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.email_share_subject));
emailIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.email_share_message));
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(temp));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
if u Send Jpg image on sen mail...just write i.setType("image/jpeg"); and send any file just write i.setType("image/*");
i've done for send any file from SD card with mail attachment..
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("rar/image");
sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new
File("/mnt/sdcard/download/abc.rar")));
startActivity(Intent.createChooser(sendEmail, "Email:"));

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..."));

Showing zero byte pdf file in email attachment in Android

I am sending a pdf file in email attachment, attachment is going successfully in email and it is showing me in email as attachment, but when i download this pdf it having no content i.e. it's size is zero byte.
Am I missing some permission? or Any solution regarding this?
Here is my code
private void emailSend(String emailString, String subject, String pdfPath){
String[] email = { emailString };
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"MY body");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
Finally i got the solution to my problem from this post.
I use
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(pdfPath)));
instead of
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(pdfPath));
it resolved my issue.
Thanks
I've done this for sending any file from SD card with mail attachment...
Intent sendEmail= new Intent(Intent.ACTION_SEND);
sendEmail.setType("rar/image");
sendEmail.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new
File("/mnt/sdcard/download/abc.rar")));
startActivity(Intent.createChooser(sendEmail, "Email:"));

how to display attach image from mail

Intent emailIntent = new Intent(Intent.ACTION_SEND);
Uri U=Uri.parse("c:/logo.png"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"sivafarshore#yahoo.com");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
startActivity(Intent.createChooser(emailIntent, "Email:"));
I am using this kind of coding for attach image file,this code sent attach with email,but that attach file dose not contain no image,what can i do for display attach image file.
Hey... it seems you are trying to attach something that is inside your C: drive. That's not possible :) You can only attach images on the sdcard folder of the handset. For instance:
Intent emailIntent = new Intent(Intent.ACTION_SEND);
Uri U=Uri.parse("file:///sdcard/logo.png");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,"sivafarshore#yahoo.com");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "This is email's message");
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
startActivity(Intent.createChooser(emailIntent, "Email:"));
To know where the sdcard folder is mounted, you use the Environment.getExternalStorageDirectory() method.

Categories

Resources