I'm trying to send some HTML formatted text via the ACION_SEND Intent in my app. The HTML file is located in my assets directory and it has links to some images and contains other CSS stylings. Thus far I've tried the following:
private Intent getEmailIntent(String deepLink) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
// sharingIntent.setType("text/html");
sharingIntent.setType("text/plain");
// sharingIntent.setType("message/rfc822");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getShareSubject());
sharingIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(getHtmlTextFromAssetsFile("myHtml.html")));
return sharingIntent;
}
As you can see from the above method, I've tried using all three of the IntentTypes in the code, without success.
The HTML file has CSS within a <style> tag , and that is not applied. It just shows up as plain text in all cases. No images (remotely located) are loaded. And </br> tags are ignored.
Has anyone worked with this? How can I get my app to send such an email? Any pointers would be helpful.
Probably not many email clients on Android support HTML. What you can do is providing plain text in EXTRA_TEXT and putting the HTML in EXTRA_HTML_TEXT as documented here: https://developer.android.com/reference/android/content/Intent.html#ACTION_SEND
Related
I want to send Html via mail app, problem is with CSS is not working when I am using Gmail to compose/send mail
And here is the intent spinet
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "Summary");
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml("<div style='background: red;'>TEST</div>"));
intent.putExtra(Intent.EXTRA_HTML_TEXT, "<div style='background: red;'>TEST</div>");
intent.setType("text/html");
startActivity(Intent.createChooser(intent, "Send mail"));
Even I applied inline CSS its not working, Can Any help what's wrong am I doing
Gmail cuts off the head, so the CSS gets lost. For HTML Emails, you should always use inline styles.
Edit:
The general rule to use inline styles is still true, but in your specific case, it seems to be an issue with sending a HTML Mail with an Intent. I found in another answer on SO, that this may isn't possible.
May be this question is already asked or duplicate of another question, but I didn't get any solution for my search.
Here are the links which I followed for my question:
Link1 Link2
Actually, my question is related to sharing HTML text in android default intent with an ACTION_SEND. When I am trying to create a hyperlink to URL with different value then it is showing a simple text of value. That is not clickable as a link.
Here is how I am doing:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
String link = "https://www.android.com/";
String linkValue = "Click Me";
String body1 = "" + link+ "";//I don't want this
String body2 = "" + linkValue + "";//This is not working
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body2));
startActivity(Intent.createChooser(intent, "Share With"));
For body2:
When I share the text using Gmail then in email hyperlinked text will come as a normal text. Simply "Click Me". I checked it on desktop browser also. But there also it is same. I checked this text in Inspect Element(You can get Inspect Element of a browser page like: Right click on browser page>> In popup window click at the bottom Inspect OR refer Inspect Element) format and found there was no tag for hyperlink text.
For body1:
It's working and I got the URL as a hyperlink in the email, but I got the URL as a hyperlink I don't want to show the same URL in email rather than there should be some hint value as body2 format. This format can be achieved by direct URL sharing in the body no need of tag.
So finally my search is, Is there any way in Android for sharing hyperlink text with different hint value rather than as of link(URL).
I suggest you use a string resource instead of a Java string, it's generally and good practice and that way you won't have to escape the " either. And with the HTML data you'll have to wrap it in CDATA.
XML:
<string name="readyandroid"><![CDATA[readyandroid]]></string>
in Java, replace body2 with:
String body2 = getString(R.string.readyandroid);
Then try passing it to the intent and sending it in an email, it should be a proper hyperlink as you would like it to be.
What you do in body is perfectly correct.
But Gmail reads the extra android.intent.extra.TEXTas a string.
You are in fact making a feature request / reporting a bug.
android:autoLink="web|email"
Please add this code in textview xml. It will directly goes gmail link
I don't think you can do using email Intent. Send email without intent Make email client for sending email. That will support HTML tag.
plz refer
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android
After you put your String to extra, it lose it attributes as Spanned. If you would send it as html, it can be resolved by some applications and shown as you want. Generally, you just put a plain text into the Bundle of your Intent, and each application interprets it as it wish, so there is no solution to send it as html and force applications to show it as html.
On the other hand, if you know which applications you're going to use via share, you can read its documentation and check if it allows to send hyperlinks via ACTION_SEND intent.
You can tell a receiver that a type of your text by intent.setType("text/html"), maybe some applications behavior depends on it.
Yes, I achieved this issue solution. Thanks, #Faraz.
This is my answer code, as I created tag string in string.xml
<string name="link_to_google_map"><![CDATA[LINK TO GOOGLE MAP]]></string>
And my code is like this, which works perfectly for sharing using tag in android:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
String shareText = "Thank you for using the ReadyAndroid App" + "<br />" + "Name : " + "ReadyAndroid";
shareText += "<br />" + "Address : " + "https://readyandroid.wordpress.com/ <br />Mandawa, Jhunjhunu, Rajasthan 333704";
String mapLocation = String.format(getString(R.string.link_to_google_map), 28.0500, 75.1487);
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(shareText+mapLocation));
startActivity(Intent.createChooser(intent, "Share with"));
I have looked around the web but have yet to find a solution that fits my specific need. I am looking for a way to share information with a share intent that provides a clickable link, something like:
Check out this news article
via Jimmy's News App
I have successfully set up a share intent in my android app which looks like this:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject Text");
shareIntent.putExtra(Intent.EXTRA_TEXT, "Check out this news article" + "\n\n" + getResources().getText(R.string.shared_via));
shareIntent.setType("text/plain");
startActivity(Intent.createChooser(shareIntent, "Share this article with..."));
My string resource looks like this:
<string name="shared_via">via <a ref="http://google.com">Jimmy's News App</a></string>
The sharing functions as it should however when shared in an Email, Twitter, etc. the link is ignored and the tweet shows only plain text like this:
I tried playing around with the MIME type, but still no cigar. Is there anyway to get "Jimmy's News App" clickable when shared? I am more than greatful for any and all help and or tips.
Thanks in advance!
First, I wouldn't have expected your project to even build, as string resources do not support arbitrary HTML tags. The only documented ones are <b>, <i>, and <u>.
Second, even if it does support arbitrary HTML tags, you are converting it back from a Spanned (getText()) into a plain string, which will remove that formatting.
To overcome both problems, either move that string into Java (after all, it's not like you have i18n going, with hardcoded English elsewhere in your code snippet), or wrap the string content in a CDATA (while also fixing your broken HTML, to use href for the <a> attribute):
<string name="shared_via"><![CDATA[via Jimmy's News App]]></string>
At this point, if you look at your concatenated string, it should look like quasi-HTML source:
Check out this news article
via Jimmy's News App
Next, while you are sending over HTML, you are declaring it as plain text. Many apps will therefore treat it as plain text, and may do anything from ignoring the tag to showing the raw HTML. You are welcome to try text/html as a MIME type and see if you get better results.
Finally, there is no requirement that any app actually honor your links. ACTION_SEND is a request, not a command. There are no rules for how third-party apps use the HTML that you send over, and so you are going to get varying results from varying apps.
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 want compile an email with HTML content which users can see before send it.
I use an
Intent email = new Intent(Intent.ACTION_VIEW);
But I cannot see an HTML interpreted, see the image below:
There is a way to show an HTML interpreted email content?
Thanks a lot
you have to set type for intent :see this method:http://developer.android.com/reference/android/content/Intent.html#setType%28java.lang.String%29
you ahve to add also this line for it shows like html for ur data:
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));**strong text**