Email issue (send hyperlink in email body) android - android

mIntent = new Intent(Intent.ACTION_SEND);
mIntent.putExtra(Intent.EXTRA_SUBJECT, getString(""));
mIntent.setType("text/html");
Uri myUri = Uri.parse("http://www.Google.com/");
mIntent.putExtra(android.content.Intent.EXTRA_TEXT,Html.fromHtml("Link"));
startActivity(android.content.Intent.createChooser(mIntent, "Email:"));
I tried the above code but at receiver side I can not get Link. it convert into normal text..

Try this one..
It is working for me..
String link_val = "www.google.com"
String body = "" + link_val+ ""
intent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));

CapDroid's answer does not look like it solves the problem, as per scottytab's comment.
Try;
yourIntent.setType("text/html");
yourIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(body));
If that doesn't work try adding;
yourIntent.putExtra(android.content.Intent.EXTRA_HTML_TEXT, Html.fromHtml(body));
References; fromHtml, EXTRA_HTML_TEXT

If you make the EXTRA_TEXT a full html document by enclosing the source text in <html><body> and <\body><\html> it will work properly with GMail, that is, you can have a proper description for the link.
Unfortunately, it won't work with all email apps. For example it does not work with the Samsung email app on my Galaxy S3. My conclusion is that you cannot safely do this, which is very annoying.

Related

How to pass hyperlink to Gmail in Intent ACTION_SEND?

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

sending html mail if app allows

I want to send a html mail from my application.
I know that not all mail clients allow html tags.
But I found the constant Intent.EXTRA_HTML_TEXT in the API (http://developer.android.com/reference/android/content/Intent.html#EXTRA_HTML_TEXT).
My code looks like this, but it shows always just the text and not the html formatted text whatever mail client I use:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_TEXT, "Hello World");
intent.putExtra(Intent.EXTRA_HTML_TEXT, "<html><body><h1>Hello World</h1></body><html>");
intent.setType("text/html"); // intent.setType("plain/text");
startActivity(Intent.createChooser(intent, "Choose Email Client:"));
So where is the mistake?
Sorry, not a positive answer because it doesn't seem to work, at least not in a way that's really universal and reliable. Some mailers are happy with this:
String body = "<html>something</html>";
intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(body));
Note that you don't need the new EXTRA_HTML_TEXT, it works with the older one as well. If this covers all you need then you might be OK. But if you also want to address many other possible intent receivers like Facebook, Skype or even apps like Drive or Keep, unfortunately, I couldn't find a perfect solution but I'd very much like to be proven wrong.
Basically, we have three different formats:
String body = "<html>something</html>";
Spanned html = Html.fromHtml(body);
String stripped = html.toString();
and two possible recipients:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
intent.putExtra(Intent.EXTRA_HTML_TEXT, ???);
intent.putExtra(Intent.EXTRA_TEXT, ???);
I tried all possible combinations but in any of those, there will be some well known and widely used app that doesn't want to play nicely. Either we get HTML tags embedded, or no formatting, or even no text at all...

A simple HTML Anchor Link does not show-up as a link in a received email in gmail

Thanks in advance for your help.
I am developing an Android App that, as part of its core functionality, needs to send emails between users (peer-to-peer emails, not spam). These emails need to contain a link that will open the Android App upon a user-click
The problem I am having is: when I send these emails to gmail acounts, links appear as normal text rather than as links.
Here is my code
private void sendEmail(String recepientName, String recipientEmail) {
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { recipientEmail };
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "My Title");
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(
"<!DOCTYPE html><html><body>" +
"<br>Dear " + recepientName + ",<br>" +
"Please <font>click here</font></body></html>"));
startActivityForResult(emailIntent, EMAIL_REQUEST);
}
What should I do to make these link work in received emailsin gmail ?
Again Thanks
What I discovered was that somehow (probably with great talent) I got into Google's black list.
this means that Google stripped the link out of my code and the users saw it as regular text
HERE IS THE REASONING:
My link looked like this: myAppName://parameter1/parameter2/Parameter3
The prefix ("myAppName://") allows Android to identify my App and launch it as you click on the link.
HOWEVER:
When this link was sent to a gmail account, Google's servers were able to identify that this was an invalid link (pretty cool that they check that ha!!) and they stripped the link out.
The solution was to use a real URL for App identification and Launch:
Something like: http://myhost.com/parameter1/parameter2/Parameter3
Hope that helps
android:scheme="http" and the appropriate android:host

android : email with templates

I am sending emails from my application.
I want to know if there is a way to define templates for eg :
subject: Regarding {{title}}
Body: You may be interested in the product {{title}} \b {{desc}}
I would like to define this templates in some resource file.
Thanks for your help and time.
Just construct mailto URL in accordance with RFC-2368, which includes subject and other fields. So in the end you'll have URI which can be used to start email sender activity:
Uri uri=Uri.parse("mailto:example#example.com?subject=Here goes test message");
intent = new Intent(Intent.ACTION_SENDTO, uri);
activity.startActivity(intent);
Futhero you can programmatically construct mailto URL as you want
You can put in strings.xml w/ string format character like %d %s %f..., and make use of String.format().
It's nice if others have better ideas :)

How to send HTML email

i found a way to send plain text email using intent:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new
String[]{"example#mail.com"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test");
But I need to send HTML formatted text.
Trying to setType("text/html") doesn't work.
You can pass Spanned text in your extra. To ensure that the intent resolves only to activities that handle email (e.g. Gmail and Email apps), you can use ACTION_SENDTO with a Uri beginning with the mailto scheme. This will also work if you don't know the recipient beforehand:
final Intent shareIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "The Subject");
shareIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<small><p>More content</p></small>")
.toString())
);
Been trying to send html via gmail app for a while, so decided to leave some insight on what I found, just in case someone else is having similar issues.
Seems like no matter what I did, I couldn't get the html to have bold text in it.
Then I've tried switching to outlook client and to my surprise it was working just fine.
Html markup was also working on other older devices, but not on mine (galaxy s7 API 26), so I figured, that gmail app seems to have dropped support for html syntax that comes from intent or maybe now you're required to provide it in some very specific way which is not clearly documented.
Last gmail version that worked for me was version 6.9.25... on Nexus 5X API 25 emulator (Nougat)
And it stopped working starting version 7.5.21... On Nexus 5x API 26 emulator (Oreo)
This was very helpful to me for the HTML, but the ACTION_SENDTO didn't quite work for me as is - I got an "action not supported" message. I found a variant here which does:
http://www.coderanch.com/t/520651/Android/Mobile/no-application-perform-action-when
And here's my code which combines the two together:
String mailId="yourmail#gmail.com";
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto",mailId, null));
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject text here");
// you can use simple text like this
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,"Body text here");
// or get fancy with HTML like this
emailIntent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append("<p><b>Some Content</b></p>")
.append("<a>http://www.google.com</a>")
.append("<small><p>More content</p></small>")
.toString())
);
startActivity(Intent.createChooser(emailIntent, "Send email..."));
I haven't (yet) started Android development, but the documentation for the intent says that if you use EXTRA_TEXT, the MIME type should be text/plain. Seems like if you want to see HTML, you'd have to use EXTRA_STREAM instead...
You must to change "EXTRA_TEXT" for "EXTRA_HTML_TEXT"
https://developer.android.com/reference/android/content/Intent.html#EXTRA_HTML_TEXT
What about just trying to add some html in the text area?
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "<strong>Test</strong>");

Categories

Resources