收藏
回答

小程序为什么无法获取到手机的蓝牙地址


不明白为什么无法获取到手机的蓝牙地址


/*开启蓝牙设备*/
openBluetoothAdapter: function () {
  var that = this;
  wx.openBluetoothAdapter({
    success: function (res) {
      console.log(res)
      wx.onBluetoothAdapterStateChange(function (res) {
        console.log("蓝牙适配器状态变化", res)
        that.setData({
          isbluetoothready: res.available,
          searchingstatus: res.discovering
        })
      })
      that.startBluetoothDevicesDiscovery()
 
    }
  })
},
/*获取本机蓝牙适配器状态*/
getBluetoothAdapterState: function () {
  var that = this;
  wx.getBluetoothAdapterState({
    success: function (res) {
      console.log(res)
      if (!res.discovering) {
        that.startBluetoothDevicesDiscovery()
      }
    }
  })
},
startBluetoothDevicesDiscovery: function () {
  var that = this;
  wx.startBluetoothDevicesDiscovery({
    allowDuplicatesKey: true,
    success: function (res) {
      console.log(res)
    },
    fail: function (res) {
      console.log(res)
    },
  })
 
  that.onBluetoothDeviceFound();
 
 
},
/**获取在小程序蓝牙模块生效期间所有已发现的蓝牙设备,包括已经和本机处于连接状态的设备。*/
getBluetoothDevices: function () {
  var that = this;
  wx.getBluetoothDevices({
    success: function (res) {
      console.log(res)
    }
  })
 
},
/**监听寻找到新设备的事件*/
onBluetoothDeviceFound: function () {
  var that = this;
  that.getConnectedBluetoothDevices()
  console.log("search............")
 
  wx.onBluetoothDeviceFound(function (devices) {
    console.log('new device list has founded')
    console.dir(devices)
    that.getBluetoothDevices()
  })
 
 
},
/**根据 uuid 获取处于已连接状态的设备*/
getConnectedBluetoothDevices: function () {
  var that = this;
  that.createBLEConnection()
  wx.getConnectedBluetoothDevices({
    success: function (res) {
      console.log(res)
      //
 
    }
  })
},


最后一次编辑于  2018-03-31  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答