Hybrid App 使用 native.js 实现搜索蓝牙列表
来源:互联网 发布:java的annotation 编辑:程序博客网 时间:2024/06/13 08:59
Hybrid App 使用 native.js 实现搜索蓝牙列表
HTML
<div class="mui-content"> <button type="button" class="mui-btn mui-btn-blue mui-btn-block" id="bt1">搜索设备</button> <div class="mui-content-padded"> 未配对蓝牙设备 <ul class="mui-table-view" id="list1"> </ul> </div> </div>
JS
mui.plusReady(function() { var ulList = ''; var main = plus.android.runtimeMainActivity(); var IntentFilter = plus.android.importClass('android.content.IntentFilter'); var BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"); var BluetoothDevice = plus.android.importClass("android.bluetooth.BluetoothDevice"); var BAdapter = BluetoothAdapter.getDefaultAdapter(); plus.android.importClass(BAdapter); console.log("BAdapter.isEnabled():" + BAdapter.isEnabled()); if(!BAdapter.isEnabled()) { BAdapter.enable(); } var filter = new IntentFilter(); var bdevice = new BluetoothDevice(); var on = null; var un = null; var vlist1 = document.getElementById('list1'); //注册容器用来显示未配对设备 vlist1.innerHTML = ''; //清空容器 var button1 = document.getElementById('bt1'); button1.disabled = true; button1.innerHTML = '正在搜索请稍候'; BAdapter.startDiscovery(); //开启搜索 var receiver; receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', { onReceive: function(context, intent) { //实现onReceiver回调函数 plus.android.importClass(intent); //通过intent实例引入intent类,方便以后的‘.’操作 console.log(intent.getAction()); //获取action if(intent.getAction() == "android.bluetooth.adapter.action.DISCOVERY_FINISHED") { main.unregisterReceiver(receiver); //取消监听 button1.disabled = false; button1.innerHTML = '搜索设备'; console.log("搜索结束"); } else if(intent.getAction() == "android.bluetooth.adapter.action.DISCOVERY_STARTED") { console.log("开始搜索设备"); } else { BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); //判断是否配对 console.log("蓝牙设备:" + BleDevice.getName() + ' ' + BleDevice.getAddress()); var li = document.createElement('li'); li.setAttribute('class', 'mui-table-view-cell'); var p1 = document.createElement("p"); p1.appendChild(document.createTextNode('名称:' + BleDevice.getName())); var p2 = document.createElement("p"); p2.appendChild(document.createTextNode('地址:' + BleDevice.getAddress())); li.appendChild(p1); li.appendChild(p2); vlist1.appendChild(li); } } }); filter.addAction(bdevice.ACTION_FOUND); filter.addAction(BAdapter.ACTION_DISCOVERY_STARTED); filter.addAction(BAdapter.ACTION_DISCOVERY_FINISHED); filter.addAction(BAdapter.ACTION_STATE_CHANGED); main.registerReceiver(receiver, filter); //注册监听});
0 0
- Hybrid App 使用 native.js 实现搜索蓝牙列表
- Native/Hybrid/Web App
- Web App、Hybrid App与Native App
- web app native app hybrid app
- Web App、Hybrid App、Native APP对比
- Web App、Hybrid App、 Native App
- Hybrid App、web-app、native-app区别
- native app, mobile web, hybrid app
- 如何判断一款app使用原生实现,还是Hybrid APP
- h5+runtime Native.js 混合APP连接蓝牙打印机
- Native.js学习(一):用5+SDK创建Hybrid App工程
- 手机App: Web App、Hybrid App、 Native App
- Hybrid (Native + Web) Mobile App Development
- 【APP开发】【hybrid】【native】越来越【统一】了
- Hybrid APP --- OC,JS 混编
- Hybrid App--介于Native App和Web App两者之间
- Native APP、WEB APP与Hybrid APP的区别
- 移动开发 Native APP、Hybrid APP和Web APP介绍
- java从ftp服务器上传下载文件
- golang http 请求未释放造成的错误
- PHP数组常用函数分类整理
- 安装 ruby
- Java 用Jackson进行json和object之间的转换(并解决json中存在新增多余字段的问题)
- Hybrid App 使用 native.js 实现搜索蓝牙列表
- MySQL 5.7版 解决密码登录失败Access denied for user 'root'@'localhost' (using password: NO)
- 使用getJSON()方法异步加载JSON格式数据
- BottomBar使用
- String、StringBuffer与StringBuilder之间区别
- 二叉树的镜像
- html5二维码扫描功能实现
- linux 环境配置 tomcat的jdk
- js - ckeditor 文本编辑器图片上传至服务器显示