WebView于JS之间相互掉用

掉用js方法


掉用:

String result = "javascript:showImage(\""+file+"\")";
this.webView.loadUrl(result);

添加

function showImage(param){

}



掉用java方法


添加:

webView.addJavascriptInterface(new CameraInterface(this), "CameraInterface");

掉用:

window.CameraInterface.openCamera("heller");



public class CameraInterface {

    private OpentCamera mContext;

    public CameraInterface(OpentCamera context){
        this.mContext = context;
    }

    @JavascriptInterface
    public String Test() {
        Logger.d("-----------", "当前被掉用");
        return "aaaaa";
    }


    /**
     * 打开相机
     * @param path
     */
    @JavascriptInterface
    public void openCamera(String path) {

        Logger.d("-----------", "当前被掉用");
        mContext.createCamertLinear();
    }

    public interface OpentCamera {

        void createCamertLinear();

    }






上一篇:Android监测到任何地方抛出的未扑获到的异常,在Application


下一篇:谈谈Android 6.0运行时权限理解