Skip to content

jin404861445lan/AndroidAndJs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

AndroidAndJs

Android java代码和Js相互调用

java调用js代码

1.无参数,java掉js代码

mWebView.loadUrl("javascript:javacalljs()");

2.带参数调用(直接在js方法拼接参数)

String hello = "hello";

mWebView.loadUrl("javascript:javacalljswithargs('" + hello + "')");

image

 public void onClick(View v) {
    switch (v.getId()) {
        case R.id.btn_calljs:

            //无参数,java掉js代码
            mWebView.loadUrl("javascript:javacalljs()");
            break;
        case R.id.btn_calljs_withparam:
            String hello = "hello";
            mWebView.loadUrl("javascript:javacalljswithargs('" + hello + "')");
            break;
    }
}

###欢迎关注虚实科技微信公众号,获得最新的技术和科技资讯

About

Android中Java代码和Js相互调用

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published