Get HitTestResult for an arbitrary point

I would like to know which object is at an arbitrary (x, y) point in WebView

, preferably without forcing anything to change on the page. I am developing an Android accessibility application where the target of the link needs to be identified before the link is activated; long clicking on the link is (unfortunately) not an option.

getHitTestResult

does basically what I want, but only for the current "cursor node". I can't find any documentation about this "cursor node", but I suspect the target point requires a touch event to appear.

+3


source to share


1 answer


Can't find the node element from point, but if you want to override the link-triggered event binding to the webview, you can do this:

add the WebViewClient to the webview using the setWebViewClient method. Then override the shouldOverrideUrlLoading () method and check the given target url

hint

: if it returns true the url will not be loaded as that means your native app is processing it.



example code:

 webview.setWebViewClient(new WebViewClient() {
         public boolean shouldOverrideUrlLoading(WebView view, String url) {
              if (isUrlGood(url))
                  return false; //the webview can load the url
              else
                  return true; //avoid the webview from loading this url
         }
 });

      

0


source







All Articles