In Android's WebView, the HitTestResult class is used to retrieve information about the HTML elements that the user interacts with, such as when tapping on a link or an image. However, by default, the HitTestResult may not return the anchor (<a href>) elements when tapping on a link.

To get the information about anchor links (<a href>) using HitTestResult, you can set the WebView's WebViewClient and override the shouldOverrideUrlLoading() method. This method is called when the user taps on a link, allowing you to inspect the URL and handle the navigation manually.

Here's an example of how to achieve this:

  1. Set WebViewClient:
  1. Get the HitTestResult:

With this setup, when the user taps on an anchor link (<a href>), the HitTestResult should return the correct URL, and you can handle the navigation or other actions manually in the shouldOverrideUrlLoading() method.

Remember that handling URL loading manually allows you to implement custom behavior, but you should also consider handling the back navigation and other WebView-related functionalities if required.

Have questions or queries?
Get in Touch