蓝牙功能,Android获得的advertisData内容不全
对wx.getBluetoothDevices(OBJECT)获得的advertisData进行操作,相同的代码,IOS获取到的advertisData下有5个字节,是所需要的广播内容,但Android获取到的advertisData下只有三个字节,相对于IOS少了前面两个字节的内容。想问下这是我自己获取方式不对吗?还是目前小程序对应Android有部分功能不支持?
//获取所有已发现的蓝牙设备 getBluetoothDevices: function (){ var that = this ; wx.getBluetoothDevices({ success: function (res){ // success var devices = res[ 'devices' ]; var newDeviceItems = []; var device = []; for ( var i=0;i<devices.length;i++) { device = devices[i]; if (device[ "name" ] != "未知设备" ){ var arryBuffer = new ArrayBuffer(); arryBuffer = device[ "advertisData" ]; var uint8Array = Array.prototype.map.call( new Uint8Array(arryBuffer), x => ( '00' + x.toString(16)).slice(-2)).join( '' ); var dataView = new DataView(arryBuffer); console.log(device[ "deviceId" ]); var len = dataView.byteLength; console.log( "len: " +len); console.log(uint8Array); var flag = true ; for ( var j=0;j<newDeviceItems.length;j++){ if (newDeviceItems[j].deviceId == device[ "deviceId" ]){ flag = false ; break ; } } if (flag){ newDeviceItems.push({deviceName:device[ "name" ],deviceId:device[ "deviceId" ]}); } } } that.setData({ deviceItems: newDeviceItems }) }, fail: function (res) { // fail console.log( "getBluetoothDevices-fail" ); console.log(res); }, complete: function (res) { // complete console.log( "getBluetoothDevices-complete" ); console.log(res); } }); } |