penguru
penguru

Reputation: 4370

Javascript in Android webView

I'm trying to do something a little tricky. I have an activity which has a webView inside. This web view is loading an external html file which has some javascript functions.

My activity is producing some reults periodically and I want to access these results in javascript functions. I thought writing output results to a file and reading in javascript side might be a solution. But I'm not sure about it.

Is there a way for doing sth like this ?

I know that we can navigate to android functions from javascript, but it is not exactly what I need.

Thanks..

Upvotes: 1

Views: 926

Answers (1)

Gavriel
Gavriel

Reputation: 19237

If you need the results only once, and on the fly, then you could try not to write them to a file but to inject it to the WebView as javascript. For example in your page you could add a function:

function newData(jsonObj) {
    ...
}

and instead of writing to a file you would call this with your actual data.

webview.loadUrl("javascript:(newData({a:1, b:2,...}))");  

Upvotes: 2

Related Questions