Android webview javascript Interface not working properly -


really not have ideal why doesn't work. basically, trying this.

 public void testjs() {         final webview webview = (webview) findviewbyid(web); //        webview.getsettings().setdomstorageenabled(true);         webview.getsettings().setjavascriptenabled(true);         webview.addjavascriptinterface(new jsinterface(webview), "sample");         webview.setwebchromeclient(new webchromeclient() {             @override             public boolean onjsalert(webview view, string url, string message, jsresult result) {         /* whatever need here */                 log.e("chrome", "asdf");                 return super.onjsalert(view, url, message, result);             }           });         webview.loadurl("javascript:window.sample.doechotest();void(0);");     } 

and jsinterface

   public class jsinterface {         webview mappview;          public jsinterface(webview appview) {             this.mappview = appview;         }          public void doechotest() {             log.e("sample", "test details");             toast toast = toast.maketext(mappview.getcontext(), "sample test details", toast.length_short);             toast.show();         }     } 

the javascript code never runs.

basic functions alert works :

webview.loadurl("javascript:alert('sample')"); 

why webview.loadurl("javascript:window.sample.doechotest();void(0);"); not working ?

just browsing different answer, guess @ haven't exposed accessible js. need explicitly each method so:

@javascriptinterface public void doechotest() {             log.e("sample", "test details");             toast toast = toast.maketext(mappview.getcontext(), "sample test details", toast.length_short);             toast.show();         } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -