Embedding image in email in Android - android

Is it possible to programatically embed an image in the body of an email sent by the Mail app in Android?
Can I use the ACTION_SEND intent to do this, or should I compose the email myself?

to put the image in the body, you need to set the content type to "text/html" and then put an img tag in the email body. if you don't want to use a webserver to host the image, then you can use a data uri for the image.
Info & Sample:
<img src="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP
C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA
AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J
REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq
ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0
vr4MkhoXe0rZigAAAABJRU5ErkJggg==" alt="Red dot" />
If you want to attach an image to the email, you use the putExtra method and set it to EXTRA_STREAM.
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, myImageStream);

If your image (or file) is in the SD card, you can proceed as follow:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/your_path_in_the_sd_card/your_image.png"));
startActivity(shareIntent);
If you don't want to send image, you need to modify the MIME in the "setType()" method.
For more details check this post.

Related

how to send picture through email if we having a picture in base64 format in android?

i want to send picture with message through email and I also want to show that picture in my email body.,i have tried this code but it is not working ,what i do.here is My code:
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
emailIntent.setType("text/html");
Uri uri = Uri.fromFile(getFileStreamPath( "<img src=data:image/*;base64,#mediaUrlBase64#\">"));
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(emailIntent);
here is the photo:-
thankyou...:)
Tried:
I had used bold tag and anchor tag as i shown below these tag are working fine , but when i used img tag i can able to see a square box which say as OBJ:
i.putExtra(Intent.EXTRA_TEXT,Html.fromHtml("<b>Hi</b><a href='http://www.google.com/'>Link</a> <img src='http://url/to/the/image.jpg'>",
imgGetter,
null));
i.setType("image/png");
And also tried this:
"<img src=\"http://images.anandtech.com/doci/3982/HTCSurround-0134.jpg\">"
But no luck. I found some answer from SO and found that unfortunately, it's not possible to do this with Intents.
The reason why for example bold text is displayed in the EditText and not an Image is that StyleSplan is implementing Parcelable whereas ImageSpan does not. So when the Intent.EXTRA_TEXT is retrieved in the new Activity the ImageSpan will fail to unparcel and therefore not be part of the style appended to the EditText.
Using other methods where you don't pass the data with the Intent is unfortunately not possible here as you're not in control of the receiving Activity.

How to embed image to E-Mail Body in Android?

I want to Embed image to E-Mail body.How to do that.I found a lot but still cannot get the solution yet.Is it possible to add an image to E-Mail body?
use Below code
Intent attachmentIntent = new Intent(Intent.ACTION_SEND);
attachmentIntent.setType("image/*");
attachmentIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("your file address"));
startActivity(attachmentIntent);

Android: Share Text & Image (URL) Via Intent

I am trying to share text with an image via an ACTION_SEND intent. The catch is that the image is represented by a URL, not a local URI. The code I currently have is:
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, text); // <- String
shareIntent.putExtra(Intent.EXTRA_STREAM, url); // <- URL object
Now I've tried a few variations on this. I've tried with setType("image/*"), I've tried parsing a Uri from the URL, I've tried passing the URL string itself, etc. Nothing so far seems to work. However, when sending to twitter I do see the text, just not the image.
Edit:
Apparently the original description was not helpful enough, so....when I launch the above intent it successfully opens a chosen application like Twitter, or Facebook, or Gmail, or Text Messaging, but an image appars in NONE of these apps. The text appears in Twitter - I can't remember if the text appears elsewhere, but my focus at this moment is on the image part anyway.
You won't be able to share on Facebook in that way because of Facebook's policy as it says in a known bug:
API does not support pre-filling the message for users
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.setType("image/*");
sharingIntent.setPackage("com.whatsapp");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
sharingIntent.putExtra(Intent.EXTRA_TEXT,videoPos);
sharingIntent.putExtra(Intent.EXTRA_STREAM,getImageUri(getApplicationContext(), bitmap));

Problems sharing combined text and image with SHARE INTENT on Twitter

I want to give the user the possibility to share a Image and a Text with Twitter and Facebook.
Actually my code can launch Android's share intent and if the user selects Facebook, all works fine, the Image is attached and the text is shown on the body of the new status.
But something is wrong with Twitter, if i only put a Image all works fine, the image is detected by twitter and automatically uploaded to twipic, then twitter posts the link of the image on the tweet. But if i put a image and a text, then, twitter doesn't detect the image and it only puts the text on the tweet, the image is ignored. What is wrong?
this is my code:
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("file:///sdcard/image.jpg");
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
You can still try with ACTION_SEND, without using the ACTION_SEND_MULTIPLE.
ACTION_SEND_MULTIPLE resulted in a force close, when I tried to create new intents for sharing to Gmail, G+, etc.
This worked perfect for me:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
Uri uri = Uri.parse("file:///sdcard/image.jpg");
shareIntent.setType("*/*");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Body text of the new status");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
return shareIntent;
Specify MIME type also for the text. "text/plain" is the type of text data MIME. Try using "*/*" as MIME, so you can send any generic data type.
Also try changing ACTION_SEND to ACTION_SEND_MULTIPLE which specialized for delivering multiple data.
More info about ACTION_SEND_MULTPLE and handling MIME types:
http://developer.android.com/reference/android/content/Intent.html

send image from ImageView as email attachment

How can I know filename of ImageView image?
I want to send it as email attachment.
UPDATE: I don't use images from resources. I have images from android storage(as in contacts app) using:
new Intent(Intent.ACTION_GET_CONTENT, null);
and from camera. Camera is OK - I can get filepath. But storage is question
If the image is a resource that you provide then you can get the path to the image. The format is:
"android.resource://[package]/[res id]"
[package] is your package name
[res id] is value of the resource ID, e.g. R.drawable.example
You can then pass this as an extra in your create e-mail intent like this:
Intent sendIntent = new Intent(Intent.ACTION_SEND);
//Mime type of the attachment (or) u can use sendIntent.setType("*/*")
sendIntent.setType("image/jpeg");
//Subject for the message or Email
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "My Picture");
//Full Path to the attachment
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("android.resource://your.package.name/" + R.drawable.example));
//Use a chooser to decide whether email or mms
startActivity(Intent.createChooser(sendIntent, "Email:"));
The short answer is that you can't, as images can be from a variety of sources. What you can do is get the bitmap cache with the same result of sending the image.

Categories

Resources