WebView中js调用java

记录下,等会在加上一个js传多个参数的代码。代码很简单,是调用QR扫描器的一个事件。


<li><a id="guide" href="javascript:window.oa_main.qr_scan()">
<img src="./img/iLeopauR.png" alt="Guide" height="72" width="72" />
<span>二维码扫描</span>
</a></li>



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
// this.initContacts();
web = (WebView) this.findViewById(R.id.web);
web.getSettings().setAllowFileAccess(true);
this.web.getSettings().setSupportZoom(false);
this.web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
this.web.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);
web.getSettings().setJavaScriptEnabled(true);

// web.setWebChromeClient(new MyWebChromeClient());
web.addJavascriptInterface(new MyJavaScriptInterface(), "oa_main"); // 定义oa_main,为OA面板使用

//web.addJavascriptInterface(new OaSystemInterface(), "oa_sys"); //注册和登录js接口
web.loadUrl("file:///android_asset/index.html");
super.onStart();
}
final class MyJavaScriptInterface {
MyJavaScriptInterface(){}
public void qr_scan() {
Intent intent = new Intent("com.google.zxing.client.android.SCAN_bluehood");
startActivityForResult(intent,BARCODE);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值