js与java通信

js 调用java中的接口并传递参数给客户端处理方式:

webView.addJavascriptInterface(new NewsDetail() , "newsDetail");

 

protected final class NewsDetail {
  
  @JavascriptInterface
  public void getContent(String imgUrl,String lineLink,String descContent,String shareTitle) {
   Logger.d("获取到了新闻详情imgUrl=" + imgUrl);
   Logger.d("获取到了新闻详情lineLink=" + lineLink);
   Logger.d("获取到了新闻详情descContent=" + descContent);
   Logger.d("获取到了新闻详情shareTitle=" + shareTitle);
   name = shareTitle;
   content = descContent;
   webUrl = lineLink;
   shareImageUrl = imgUrl;
  }
 }

 

js调用:newsDetail.getContent(imgUrl,lineLink,descContent,shareTitle);

 

java调用js中的方法:webView.loadUrl(String.format("javascript:java3js()"));

posted @ 2014-09-19 10:39  疯子FK  阅读(906)  评论(0编辑  收藏  举报