蓝牙搜索问题

发布于 7 年前作者 nazou4900 次浏览最后编辑 7 年前来自 ask
Page({
  data:{
    msg_1 : "",
    msg_2: "",
    msg_3: ""
  },
  onLoad: function () {
     
  },
  searchBlueBtn: function (e) {
    this.openBluetooth();
  },
  //初始化蓝牙模块
  openBluetooth: function (e) {
    var that = this;
 
    wx.openBluetoothAdapter({
      success: function (res) {
        that.startBluetooth();
 
        that.setData({
          msg_1: "msg_1" +JSON.stringify(res)
        })
      }
    })
  },
  //开启蓝牙搜索
  startBluetooth:function(e){
    var that=this;
 
    wx.startBluetoothDevicesDiscovery({
      success:function(res){
        that.getBluetoothDevices();
 
        that.setData({
          msg_2: "msg_2" +JSON.stringify(res)
        })
      }
    })
  },
  //开始搜索附近蓝牙设备
  getBluetoothDevices: function (e) {
    var that = this;
 
    wx.getBluetoothDevices({
      success: function (res) {
     
        that.setData({
          msg_3: "msg_3" +JSON.stringify(res)
        })
 
        that.closeBluetooth();
      }
    })
  },
  //关闭蓝牙
  closeBluetooth: function (e) {
    wx.stopBluetoothDevicesDiscovery({
      success: function (res) { }
    })
 
    wx.closeBluetoothAdapter({
      success: function (res) { }
    })
  }
})

昨天测试的时候,蓝牙设备列表是时有时无,今天测试的时候是一直没有过。。。。手机也重启过了,也是一样,用的是安卓手机。请问是什么问题啊

6 回复
lijing
lijing1 楼6 年前

好的,谢谢。

请问搜不到蓝牙列表有人知道是什么问题吗

ayuan
ayuan2 楼6 年前

可以的

chaolong
chaolong3 楼6 年前

请问怎么实现?我上次写入成功没有打印出来纸,官方有人说是要低功耗协议的打印机才行。我现在好迷茫阿

leilin
leilin4 楼6 年前

借地问一下,蓝牙有什么用?我想打印订单的话可以用小程序连接蓝牙打印机吗?求大神指点一下

jun59
jun595 楼6 年前

找到问题了

wx.onBluetoothDeviceFound 要在 wx.getBluetoothDevices 的前面

lzhao
lzhao6 楼5 年前

哥,你搜索到设备之后,stop就可以,不用close啊