I am having some trouble getting the selection from a WebView in Android.
I can get the WebView to go into selection mode. I can even get it to copy the text to the
Finally, in Android 4.4 KitKat, the WebView is now based on Chromium.
Therefore we have access to window.getSelection()
!!
wv.evaluateJavascript("console.log(window.getSelection().baseNode.nodeValue);", null);
Tested on Nexus 5 & Nexus 7.
When the WebView goes into "Selection Mode", the WebView is not actually being used for selection... It is being pushed under a "WebTextView" (private class in Android's arsenal) which mimics the text position, yet allows images to show through, and allows you to "select" the text which appears in the actual HTML. The problem comes when you try to interact with the WebView after "selecting" the text. The highlight and cursor handles are in the right position, but they are actually in the special WebTextView I mentioned, therefore you do not actually have a selection to get via JavaScript's getSelection, or any other means in JavaScript. I am working on making the ACTION_DOWN (of the LongPress) which triggers selection and the drag and ACTION_UP of the release from drag work for me via JavaScript, but it is very hairy, and not at all user friendly at this point...
http://www.java2s.com/Open-Source/Android/android-core/platform-frameworks-base/android/webkit/WebTextView.java.htm
check the source(that's a lot of work to mimic text selection instead of provide it) It is sad, and currently very painful for a project our team has undertaken -- especially after doing the same app for iPad...
You should try rangy - A cross-browser JavaScript range and selection library.