0
我在JSTest类和JSInterface下面使用获得了javascript结果 但是“processJsReturnValue”函数没有被调用。 我的错误是什么?如何在android上运行javascript并获取结果
public class JSTest {
private String jsReturnValue =null;
private WebView webView;
public Context mContext;
private static class JSInterface {
private JSTest myContext;
public JSInterface(JSTest context) {
this.myContext = context;
}
@JavascriptInterface
public void processReturnValue(String value) {
myContext.processJsReturnValue(value);
}
}
public JSTest(Context context) {
super();
mContext = context;
webView = new WebView(context);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JSInterface(this), "androidInterface");
String jsString = "(function(){"+
"window.androidInterface.processReturnValue('abc');"+
"})();";
webView.loadUrl("javascript:"+jsString);
}
public void processJsReturnValue(String value) {
Log.e("got it", value);
jsReturnValue = value;
}
}
如果你的'jsString'改变发生什么:'字符串jsString =“androidInterface.processReturnValue( 'ABC') ;“'? – Jite
它是一样的.. –
你是否100%肯定'processJsReturnValue'函数没有被调用?你在Javascript中遇到任何错误吗?或者在android端? – Jite