Reputation: 236
I have a WebView which is evaluating a javascript snippet within periodically until it returns a certain value.
This is currently being done using the two different ways depending on the SDK Version. If the application is running on a device with a Android API of 19 or higher we'll just call:
webview.evaluateJavascript('javascript:myFunctionHere()', null)
And if the Android API version is equal to or between 15 or 8 (Minimum SDK version) we'll use reflection to call:
stringByEvaluatingJavaScriptFromString('javascript:myFunctionHere()')
from the BrowserFrame class used by the WebViewCore.
What I need is a way to do this for API Version 16, 17 & 18. They rewrote the WebView class and removed the mWebViewCore field and they didn't add the evaluateJavascript() until API 19.
Using WebView.loadURL() is not an option since this is hiding the soft keyboard on the device (because the webview detects it is being redirected or something) making it impossible to input text in textboxes.
Is there a way to evaluate javascript on an existing webview without hiding the soft keyboard?
Upvotes: 1
Views: 912
Reputation: 236
Nevermind, solved it!
I was tackling the issue from the wrong angle. Instead of polling a function in the javascript from the java code periodically I made a function in javascript that made a delayed call to itself if it still needed polling and called a method in the javascript interface class if the value I wanted to return wasn't null.
That way I only needed to call loadUrl() once the page had fully loaded to start the poll and then let the javascript do the rest.
Upvotes: 1