安卓蓝牙

发布于 8 年前作者 qiang108526 次浏览最后编辑 8 年前来自 ask

今天发现小程序可以支持安卓蓝牙API了,但测试了下wx.getBluetoothDevices这个API报错!

另外向非低功耗蓝牙设备发送数据的场景如何实现?比如我要使用蓝牙便携打印机(非低功耗蓝牙)

10 回复
shaojun
shaojun1 楼6 年前

Page({

  onLoad: function () {

    //var that = this;

    wx.openBluetoothAdapter({

      success: function (res) {

        console.log(res)

        wx.getBluetoothAdapterState({

          success: function (res) {

            console.log(res)

          }

        })

        wx.startBluetoothDevicesDiscovery({

          success: function (res) {

            console.log(res)

          }

        })

        wx.getConnectedBluetoothDevices({

          success: function (res) {

            console.log(res)

          }

        })

        wx.getBluetoothDevices({

          //services: [‘0019E0A29C02’],

          success: function (res) {

            console.log(res)

            // that.setData({

            //   // BLT_name: res.devices[0].name,

            //   // BLT_deviceId: res.devices[0].deviceId,

            //   // BLT_RSSI: res.devices[0].RSSI

            //   // BLT_advertisData: res.devices[0].advertisData

            // })

          }

        })

      }

    })

  }

})  

控制台输出,就wx.getBluetoothDevices报错,其他四个API正常。

错误代码:cannot read property ‘map’ of undefined

xia98
xia982 楼6 年前

这个报错是由于发现的蓝牙设备为0的时候导致的。

如果你发现至少一个设备后,就不会报错了

shenyan
shenyan3 楼6 年前

同遇到thirdScriptError       wx.getBluetoothDevices,报错

acao
acao4 楼6 年前

怎么解决?

ming73
ming735 楼6 年前

四楼:您说蓝牙设备为0时wx.getBluetoothDevices才报错,感觉不对,手机发现的蓝牙设备有好几个(连接和不连接的),况且wx.getConnectedBluetoothDevices可以取得蓝牙设备一个,这如何解释?还是觉得这个API没做好

tao94
tao946 楼6 年前

请官方人员来解答下么?

panyong
panyong7 楼6 年前

四楼,为啥发现的蓝牙设备为0,我测试的时候,旁边有好几个蓝牙,接口有问题吧

rding
rding8 楼6 年前

刚才尝试了安卓和苹果的手机返回来的数据不一样,这样子输出出来看看就知道了,但是这个

wx.onBLECharacteristicValueChange(CALLBACK)

这个接口没有实时的数据返回来

duanmin
duanmin9 楼6 年前

有官方人员来解答下么?

xia89
xia8910 楼6 年前

7楼没错,而且,可以用另了一个方式去获取,就是通过

wx.onBluetoothDeviceFound(CALLBACK) 来获取,但实际上,手机可以发现蓝牙,但不会进入到这个事件函数中去。

所以小程序app无法发现蓝牙设备。