Android中Java和JavaScript的交互

前端之家收集整理的这篇文章主要介绍了Android中Java和JavaScript的交互前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

Java代码

myWebView.addJavascriptInterface(new JsInteration(),"control");

private void testMethod(WebView webView) {
String call = "javascript:sayHello()";
call = "javascript:alertMessage(\"" + "content" + "\")";
call = "javascript:toastMessage(\"" + "content" + "\")";
call = "javascript:sumToJava(1,2)";
webView.loadUrl(call);
}

public class JsInteration {

@JavascriptInterface
public void  toastMessage(String message) {
    Toast.makeText(getApplicationContext(),message,Toast.LENGTH_LONG).show();
}

@JavascriptInterface
public void onSumResult(int result) {
       Log.i(LOGTAG,"onSumResult result=" + result);
}

}

JavaScript代码


猜你在找的JavaScript相关文章