搜索蓝牙的时候就闪退呢,在安卓手机上运行的 用的HBuilderX
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet"/>
<script type="text/javascript" >
// 扩展API加载完毕后调用onPlusReady回调函数
document.addEventListener('plusready', onPlusReady, false);
// 扩展API加载完毕,现在可以正常调用扩展API
function onPlusReady(){
}
// 开始搜索蓝牙
function startBluetoothDiscovery(){
plus.bluetooth.openBluetoothAdapter({
success:function(e){
console.log('open success: '+JSON.stringify(e));
plus.bluetooth.startBluetoothDevicesDiscovery({
success:function(e){
console.log('start discovery success: '+JSON.stringify(e));
},
fail:function(e){
console.log('start discovery failed: '+JSON.stringify(e));
}
});
},
fail:function(e){
console.log('open failed: '+JSON.stringify(e));
}
});
}
// 获取已搜索到的蓝牙设备
function getBluetoothDevices(){
plus.bluetooth.getBluetoothDevices({
success:function(e){
var devices = e.devices;
console.log('get devices success: '+e.length);
for(var i in devices){
console.log(i+': '+JSON.stringify(devices[i]));
}
},
fail:function(e){
console.log('get devices failed: '+JSON.stringify(e));
}
});
}
// 结束搜索蓝牙
function stopBluetoothDiscovery(){
plus.bluetooth.stopBluetoothDevicesDiscovery({
success:function(e){
console.log('stop discovery success: '+JSON.stringify(e));
plus.bluetooth.closeBluetoothAdapter({
success:function(e){
console.log('close success: '+JSON.stringify(e));
},
fail:function(e){
console.log('close failed: '+JSON.stringify(e));
}
});
},
fail:function(e){
console.log('stop discovery failed: '+JSON.stringify(e));
}
});
}
</script>
</head>
<body>
<button onclick="startBluetoothDiscovery()">开始搜索蓝牙</button>
<br/>
<button onclick="getBluetoothDevices()">获取已搜索到的蓝牙设备</button>
<br/>
<button onclick="stopBluetoothDiscovery()">结束搜索蓝牙</button>
</body>
</html>
3 个回复
1***@qq.com
我也碰到这种情况 楼主解决了吗?
TYX
我也遇到啊,什么情况?解决了吗?
d***@ibeimen.com
我也遇到啊,怎么解决?