I want to implement the sharing functionality in my app. Basically, the shared message will be just some text and links. The issue is that the links might sometimes be too long. So, I'd like to shorten them by embedding them into hyperlink text like so.
val someText = "<p>This is <b>HTML</b> content with a <a href=\'https://google.com\'>hyperlink</a>.</p>"
val shareIntent = Intent(Intent.ACTION_SENDTO).apply {
action = Intent.ACTION_SEND
type = "text/html"
putExtra(Intent.EXTRA_TEXT, HtmlCompat.fromHtml(someText, HtmlCompat.FROM_HTML_MODE_COMPACT))
}
startActivity(Intent.createChooser(shareIntent, "Share"))
Here I just use HTML to make hyperlinked text(with Google URL as example)
What I've tried: 1) I tried putting the hyperlink text into resource XML file, 2) I tried using both "text/plain" and "text/html" as Intent type, 3) I tried different flags for the 'fromHtml' method, 4) tried using Markup instead of HTML
I expected, in this particular case to see something like this: This is HTML content with a hyperlink
Instead I just get "This is HTML content with a hyperlink". So the HTML tags are recognised, but not applied. I'd like to know if it is at all possible to share links like that on Android. Or do I have to show the full body of the link? Thanks