Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting selection changes in WebView

Tags:

People also ask

Is Android WebView deprecated?

The Android system webview custom cache file has been deprecated and removed in Android 13. New apps and any app updates will now use the operating system default cache location.

What is WebView DevTools?

WebView DevTools are a set of on-device tools to help debug your WebView apps. The best way to launch WebView DevTools is to download WebView Beta, Dev, or Canary. These channels contain a launcher icon which launches WebView DevTools.

Which browser is used in Android WebView?

Google combined WebView with Google Chrome for versions 7.0, 8.0 and 9.0. However, with Android 10.0, it went back to having it as a separate component. Users can update WebView in Android 10 through Google Play Store.

How do I view WebView?

Create two Android layout files – “res/layout/main. xml” and “res/layout/webview. xml“. Two activity classes, an activity to display a button, another activity display the WebView with predefined URL.


I was able to get the selected text using the following method:

webview.evaluateJavascript("(function(){return window.getSelection().toString()})()",
    new ValueCallback<String>()
    {
        @Override
        public void onReceiveValue(String value)
        {
            selected = value;
            Log.v(TAG, "SELECTION:" + value);
        }
    }
);

And I detect the first selection using when the motion event detected by the onTouchEvent is ACTION_UP.

webview.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        int action = event.getAction();
        if(event.getAction() == MotionEvent.ACTION_UP)
        {
           //webview started selection a word
        }
    }
});

My problem is to be able to detect when the selection changes using the handlers. Unfortunately ACTION_MOVE and ACTION_DOWN are not getting called while changing the selection using the default selection handlers.

Kindly note that when I use the ActionMode CallBack function, the default selection stops working.