html52.com
我爱小程序-开发者交流社区

蓝牙搜索问题

问题模块
API和组件


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) { }
    })
  }
})


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

网友回复

邓东:

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

吉吉:

可以的


邓东:

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

特攻007:

找到问题了


wx.onBluetoothDeviceFound 要在 wx.getBluetoothDevices 的前面

特攻007:

好的,谢谢。


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

吉吉:

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

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付