android webview不能调用JS中的function?
问题阐述:
android中使用WebView加载了带有JS的Html文件,然后调用Html中JS的function出现问题:function不被调用
private synchronized void getLocalRes() {
res = "<html><script、、 </script> <body>、、、 </body></html>";
res = URLDecoder.decode(res);
byte[] byt = Utils.readFile(OffStoreDownload.FILEROOT.
concat(OffStoreDownload.PLUGROOT).concat(res));
if (null != byt) res = new String((byte[]) byt);
//加载本地文件
ewv.loadDataWithBaseURL(null , res, "", "utf-8", "");
}
在调用getLocalRes()函数后,调用:
ewv.loadUrl(“javascript:javacalljswithargs(‘12345d’)”);
注意:synchronized不能丢,否则JS调用无效。因为加载有延迟,需要同步线程。