3

I'd like to be able to figure out what object is at an arbitrary (x,y) point in a WebView, preferably without causing anything to change on the page. I'm developing an accessibility app for Android where the target of a link needs to be identified before the link is activated; long-pressing on the link is (sadly) 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 it requires a touch event to appear at the target point.

nneonneo
  • 171,345
  • 36
  • 312
  • 383

1 Answers1

0

Not a way to find the node element from a point, but if you want to override a link clicked event fonctionnality on a webview you can do this :

add a WebViewClient to you web view using setWebViewClient method. Then override the shouldOverrideUrlLoading() method and check given target url

hint : if it returns true, the url won't be loaded since it means that your native app is handling it.

code sample :

 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
         }
 });
Guian
  • 4,563
  • 4
  • 34
  • 54
  • I need to identify the target of the link *before* the link is activated. – nneonneo Apr 12 '13 at 15:22
  • do you mean before it has been clicked ? That is more a javascript problem, implement it in javascript and make a little communication between the webview and the java code to recover it ... – Guian Apr 12 '13 at 15:36