I want to send an email from my android application which have HTML content and also an image.
I have tried this code
Intent mailIntent = new Intent(android.content.Intent.ACTION_SEND);
mailIntent.setType("text/html");
mailIntent.putExtra(Intent.EXTRA_SUBJECT, getResources().getString(R.string.subject_mail));
mailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
But i have always an icon "obj" instead of image
Related
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.
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));
Hi i am making an app in which i am dynamically getting the image from server and i want to give user the option to mail that image. I am using following code but i dont how to set path of image in below code.
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);
You set the path to the image in this line:
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file://"+file.getAbsolutePath()));
, where file is the image you want to send.
Also, note that the second call to setType will override the effects of the first call you made.
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
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.