3

Is it possible to create in Android event, which sends data to Havascript EventListener in WebView?

For example:
In background, I start thread what search updates on server. When updates was found I send event to update data on user page. And I don't want reload view.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
smie
  • 592
  • 1
  • 9
  • 25

1 Answers1

3

Currently the only way I found out was using JavaScript injection:

mWebView.loadUrl("javascript:helloWorld(\"hi\");"); //or postUrl if using HTTP POST

This will cause the function helloWorld defined in the JavaScript of the webpage to be called with parameter value hi.

RvdK
  • 19,580
  • 4
  • 64
  • 107