1

I have a string that is HTML encoded and want to decode it and detect phone numbers and URL's to make them clickable after decoding it.

I've found

Html.decode()

to decode the text and this makes links of the hyperlinks. Then if I then call

Linkify.addLinks()

to it then the hyperlinks will then lose their extended paths.

Ex:

https://www.micromentor.org/?utm_source=volunteermatch&utm_medium=post1&utm_campaign=mentorrecruitment

will become

https://www.micromentor.org

If it was already a hyperlink.

How do I HTML decode the string and linkify the string while also keep the extended hyperlink address?

if (Build.VERSION.SDK_INT >= 24)
{
    description.setText(Html.fromHtml(opportunity.getDescription() , Html.FROM_HTML_MODE_LEGACY));
}
else
{
    description.setText(Html.fromHtml(opportunity.getDescription()));
}
Linkify.addLinks(description, Linkify.ALL);
description.setMovementMethod(LinkMovementMethod.getInstance());
Jesus Garcia
  • 49
  • 1
  • 6

1 Answers1

1

You can use URLSpan or ClickableSpan to solve your problem. View this: Android TextView with Clickable Links: how to capture clicks?

Nguyen Vu Quang
  • 831
  • 6
  • 5