JavaToJsinterface.java 714 Bytes
package com.polysoft.nafmii.webview;


import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.tencent.smtt.sdk.WebView;

public class JavaToJsinterface {
    private static final String TAG = JavaToJsinterface.class.getName();
    protected WebView mWebView;

    public JavaToJsinterface(WebView webView) {
        this.mWebView = webView;
    }

    public void callJs(String methodName, String json) {
        String param = JSON.toJSONString(json);
        String script = String.format("javascript:$api.%s(%s)", methodName, param);
        this.mWebView.evaluateJavascript(script, value -> Log.d(TAG, String.format("JavaToJsinterface: callJs is %s result : %s", methodName, value)));
    }

}