Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android custom Event to Javascript EventListener

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.

like image 726
smie Avatar asked Sep 18 '26 05:09

smie


1 Answers

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.

like image 159
RvdK Avatar answered Sep 19 '26 19:09

RvdK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!