image attachment to a mail.. how in android? - android

i can pick a image and its path using intent. with the use of that path of an image. i have to set that image as attachment of the mail's body content. how its possible in android???

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getResources().getString(R.string.emlSendToFriendSubject));
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[]{emailto});
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,getResources().getString(R.string.emlSendToFriendBody));
File file = getFileStreamPath(EMAIL_TEMP_FILE);
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
startActivityForResult(Intent.createChooser(emailIntent, getResources().getString(R.string.btnSendToFriend)),ActMain.EMAIL_DONE);

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

How to share both text and image in the share intent (email and gmail)

I would like to make a share button for both gmail and the rom email app . The problem is how to share both image and text?
For the image , I can provide either file uri / bitmap / whatever need and I only need to share one image.
final Intent result = new Intent(android.content.Intent.ACTION_SEND);
result.setType("plain/text");
result.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { recipient });
result.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
result.putExtra(android.content.Intent.EXTRA_TEXT, body);
Thanks for helping
You can find ans from below code:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/jpeg");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] {""});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EMAIL_BODY);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+fileName));
startActivity(Intent.createChooser(emailIntent, "Sharing Options"));
Hope this helps..

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

Sending image by email, Android?

I'm trying to make an application to capture an image and send it by email, I successfully made it by the following code
String path = Images.Media.insertImage(getContentResolver(), bmp,"title", null);
Uri screenshotUri = Uri.parse(path);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent
.putExtra(android.content.Intent.EXTRA_EMAIL, emailAddresses);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");
startActivity(Intent.createChooser(emailIntent, "Send email using"));
But the image is sent in a small size and very low resolution ?! Any suggestions for sending the image with it's actual size and resolution ?! Or is there any other way to get a jpeg image from the camera result instead of a bitmap ?!
Thanks in advance
bmp is a Bitmap I assume? Then you can save the image by use the compress http://developer.android.com/reference/android/graphics/Bitmap.html#compress%28android.graphics.Bitmap.CompressFormat,%20int,%20java.io.OutputStream%29 method from the bitmap class to write it to a file, and then create a Uri from the file.
When you insert an image, the Uri you receive from Media can be a reduced version.
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, EMAIL_SUBJECT);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, EMAIL_TEXT);
File newFile = new File(Environment.getExternalStorageDirectory(), IMAGE_PATH);
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,Uri.fromFile(newFile));
startActivity(emailIntent);

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