'Getting link info android
how can we show some additional information about a link in android i have seen examples that open links in the browser but that is not the case what i want
TextView tv = (TextView) findViewById(R.id.textView1);
String text = "This is just a test. Click this link here <a href=\"http://www.google.com\">Google</a> to visit google.";
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(text));
I have tried some code like above but it is for opening in a browser where else i want something like the below image

Solution 1:[1]
That can be done using a URLSpan.
TextView tv = (TextView) findViewById(R.id.textView1);
SpannableString text = new SpannableString("This is just a test. Click this link here to visit google.");
text.setSpan(new URLSpan("http://www.google.com", 37, 41, 0));
tv.setText(text);
There are also several types of other Spans that can be really useful to style text. The 37 and 41 are the start and end indexes of the text to style.
Also here is an excellent blog post by Flavien Laurent on the many uses of Spans.
Solution 2:[2]
I think splitting it into 2 text views is the best option. Here is a similar thread:
android: html in textview with link clickable
Hope this helps.
Solution 3:[3]
You can use basic HTML to format your text in TextView. You can do something like bold, italic, link, etc. Here is a sample:
String code = "<p><b>First, </b><br/>" +
"Please press the link below.</p>" +
"<p><b>Second,</b><br/>" +
"Please insert the details of the event."
"<a href='http://www.google.com'>click here</a></p>";
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setMovementMethod(LinkMovementMethod.getInstance());
tv.setText(Html.fromHtml(code, this, null));
tv.setTextSize(16);
Solution 4:[4]
What you are looking for is the OG tags from the link
This can be done by using JSoup and getting the information about the link and then extracting the OG tags from that.
You can checkout a simple library I made for the same task.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Robby Pond |
| Solution 2 | Community |
| Solution 3 | Racil Hilan |
| Solution 4 | Priyansh Kedia |
