android WebView通过js方法与原生交互,android系统工程师面试题

46 阅读2分钟

@Override

public void onJsFunctionCalled(String tag) {

// TODO Auto-generated method stub

}

@JavascriptInterface

public void goToBusinessChatRoom() {

// window.yxbl_app.toChat() //js调用android源码方法,发起环信聊天

if (TextUtil.isEmpty(groupid)){

Toast.makeText(getApplicationContext(), "该群不存在", Toast.LENGTH_SHORT).show();

return;

}

gotoliaotian();

}

@JavascriptInterface

public void toCompanyDetail(String epId, String accessPath, String a) {//网页定义的方法名相同即可,同时可以传参数

// window.yxbl_app.toCompanyDetail() //js调用android源码方法

Intent intent = new Intent(BusinessDetailWebActivity.this, CompanyDetailWebActivity.class);

intent.putExtra("epId", Integer.parseInt(epId));

intent.putExtra("accessPath", accessPath);

startActivity(intent);

}

@JavascriptInterface

public void BusinessVisit(int aid,String aname,String ac,String ap) {

// Log.v("Lgq","newo[==="+aname);

// window.yxbl_app.toCompanyDetail() //js调用android源码方法

// Intent intent = new Intent(BusinessDetailWebActivity.this, CompanyDetailWebActivity.class);

// intent.putExtra("epId", Integer.parseInt(epId));

// intent.putExtra("accessPath", accessPath);

// startActivity(intent);

}

@JavascriptInterface

public void openImage(String imageUrls, String img) {

Intent intent = new Intent();

intent.putExtra("imageUrls", imageUrls);

intent.putExtra("curImageUrl", img);

Log.v("lgq","tophoto===== "+img+"..... "+ imageUrls);

intent.setClass(BusinessDetailWebActivity.this, PhotoBrowserActivity.class);

startActivity(intent);

}

@JavascriptInterface

public void gotoGongxu() {

Intent intent = new Intent();

intent.setClass(BusinessDetailWebActivity.this, GongXuActivity.class);

startActivity(intent);

}

@JavascriptInterface

public void gotoInvestment(String id) {

Intent intent = new Intent();

// web页面跳转投资列表

intent.setClass(BusinessDetailWebActivity.this, GongXuActivity.class);

startActivity(intent.putExtra("id", id));

}

}, CommonString.js2Android);

}

2、原生与webview交互:changeColor是js方法,viewColor是参数

activityBaseWebAddWebView.loadUrl("javascript:changeColor('" + viewColor + "')");

附:自定义接口

/**

文末

我总结了一些Android核心知识点,以及一些最新的大厂面试题、知识脑图和视频资料解析。

需要的小伙伴私信【学习】我免费分享给你,以后的路也希望我们能一起走下去。(谢谢大家一直以来的支持,需要的自己领取)

直接点击链接也可以领取哦!

Android学习PDF+架构视频+面试文档+源码笔记

部分资料一览:

  • 330页PDF Android学习核心笔记(内含8大板块)

  • Android学习的系统对应视频

  • Android进阶的系统对应学习资料

  • Android BAT大厂面试题(有解析)