Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On android 4.4 webView.getHitTestResult() returns null

I'm running into an issue on kitkat (Android 4.4) devices running my app. The issue is that when I call getHitTestResult() on my webview it returns null, where as on any other version of Android it returns appropriate data. I'm not sure if this is a specific 4.4 bug or if there's a work around any one is aware of. Any help is much appreciated. Code is below:

    WebView myWebView = new WebView(getContext());
    HitTestResult hitResult = myWebView.getHitTestResult();

    if (hitResult != null && hitResult.getType() == HitTestResult.SRC_ANCHOR_TYPE) {
        CBDReaderWebClient client = new CBDReaderWebClient();
        ...
    }
like image 983
CalebeGeazi Avatar asked Nov 10 '22 16:11

CalebeGeazi


1 Answers

But, do you have it inside a touch listener? As far as i know, that only work after something was touched (not in the precise moment, but something has to be touched)

WebView myWebView = new WebView(getContext());
HitTestResult hitResult = myWebView.getHitTestResult();

myWebView.setOnTouchListener(new View.OnTouchListener() {
  public boolean onTouch(View v, MotionEvent event) {
      WebView.HitTestResult hr = ((WebView)v).getHitTestResult();

       //...

      return false;
   }
 });
like image 197
Carlos Robles Avatar answered Nov 14 '22 22:11

Carlos Robles