我想从 Webview 调用 Java。
我有JavaScriptInterface
以下:
class JavaScriptInterface{
private Activity activity;
public JavaScriptInterface(Activity activiy) {
this.activity = activiy;
}
public void open(String message){
//do something
}
}
我加JavaScriptInterface
JavaScriptInterface jsInterface = new JavaScriptInterface(this);
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(jsInterface, "JSInterface");
在我的 HTML 中,我有这个 onclick 事件:
onclick="window.JSInterface.open('hi');"
我也试过:
onclick="JSInterface.open('hi');"
我在 logcat 中有这个错误:
04-16 14:55:15.829: W/dalvikvm(721): JNI WARNING: jarray 0x4050cf68 points to non-array object (Ljava/lang/String;)
04-16 14:55:15.829: I/dalvikvm(721): "WebViewCoreThread" prio=5 tid=9 NATIVE
04-16 14:55:15.829: I/dalvikvm(721): | group="main" sCount=0 dsCount=0 obj=0x40521218 self=0x1f6cf8
04-16 14:55:15.829: I/dalvikvm(721): | sysTid=729 nice=0 sched=0/0 cgrp=default handle=2059824
04-16 14:55:15.839: I/dalvikvm(721): | schedstat=( 5717972154 3300872155 567 )
04-16 14:55:15.839: I/dalvikvm(721): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
04-16 14:55:15.839: I/dalvikvm(721): at android.webkit.WebViewCore.nativeTouchUp(Native Method)
04-16 14:55:15.839: I/dalvikvm(721): at android.webkit.WebViewCore.access$3300(WebViewCore.java:53)
04-16 14:55:15.839: I/dalvikvm(721): at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1158)
04-16 14:55:15.863: I/dalvikvm(721): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 14:55:15.869: I/dalvikvm(721): at android.os.Looper.loop(Looper.java:130)
04-16 14:55:15.869: I/dalvikvm(721): at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:629)
04-16 14:55:15.869: I/dalvikvm(721): at java.lang.Thread.run(Thread.java:1019)
04-16 14:55:15.869: E/dalvikvm(721): VM aborting
如何解决?或者另一种方式来做到这一点?
谢谢