android - Cordova call JavaScript function from Java without webview -


how can call javascript function java. example have sayhello function in www/js/app.js. need write method in java call sayhello , give result using cordova.

 sayhello: function(name) {     return "hello "+name; } 

try this

//method exec javascript private static synchronized void executejavascript(final string strjs, cordovawebview mywebview) {      runnable jsloader = new runnable() {         public void run() {             mywebview.loadurl("javascript:" + strjs);         }     };     try {         method post = mywebview.getclass().getmethod("post",runnable.class);         post.invoke(mywebview,jsloader);     } catch(exception e) {         ((activity)(mywebview.getcontext())).runonuithread(jsloader);     } } 

assuming have class

public class mycordovaplugin extends cordovaplugin 

you have method

@override public void initialize (cordovainterface cordova, cordovawebview webview) {       //and call method       executejavascript("sayhello('bear')", webview); } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -