java - How to pass a Javascript function as an argument in Javascript Interface? -


how pass function parameter in javascript interface, save string , call?

for example, describe javascript interface:

class jsinterface{   string myfunction;    //set function myfunction attribute   @javascriptinterface   public void setmyfunction(string func) {     this.myfunction = func;   }    @javascriptinterface   public void executemyfunction() {     webview.loadurl("javascript:"+this.myfunction);   }  } 

add it:

//...  webview..addjavascriptinterface(new jsinterface, "application");  //... 

in js:

window.application.setmyfunction(function(){         //some code here... }); 

note: transfer function js need in form, not string or json.

but in fact, in setmyfunction "undefined" expect "window.application.setmyfunction(function(){ //some code here...});". tell me please do, grateful!

try one:

convert javascript object (incl. functions) string

then attach function call string:

function(){ .. }() 

and call eval() on string.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -