/*接口绑定*/
webView.addJavascriptInterface(new JsHook(this),"appInterface");
/*javascript交互函数*/
public class JsHook{
private Context context;
JsHook(Context context) {
this.context = context;
}
@JavascriptInterface
public void openImage(String src) {
Intent intent = new Intent();
intent.putExtra("image", src);
intent.setClass(context, ShowWebImageActivity.class);
context.startActivity(intent);
}
@JavascriptInterface
public void setReaded(){
}
}
这里需要注意的是:GOOGLE出于安全考虑,在每个调用的函数前面,一定要加上@JavascriptInterface