wx.onBluetoothDeviceFound安卓手机崩溃
发布于 6 年前 作者 zzhang 7693 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)

开启蓝牙搜索,但不设置筛选,设置interval :1000,在周围BLE设备多的时候,安卓手机搜索崩溃、闪退代码如下:

wx.openBluetoothAdapter({

  // 蓝牙打开

  success: function () {

    // 获取适配器状态

    wx.getBluetoothAdapterState({

      // 获取成功

      success: function (res) {

        // 蓝牙适配器可用

        if (res.available == true) {

          // 开始检索蓝牙设备,设置过滤条件

          wx.startBluetoothDevicesDiscovery({

            allowDuplicatesKey: true,

            interval:1000,

            success: function () {

              wx.onBluetoothDeviceFound(function (devices) {

                if (devices.devices[0].name != “未知设备” && devices.devices[0].name != “”) {

                 console.log(devices.devices[0].name)

                }

              })

            }

          })

        } else // 蓝牙适配器不可用

        {

          console.log(“bluetooth adapter is not available”)

        }

      },

      // 未获取适配器状态

      fail: function () {

        console.log(“getBluetoothAdapterState failed”)

      }

    })

  },

  // 蓝牙未打开

  fail: function () {

    wx.showModal({

      content: ‘Bluetooth switch not turned on’,

      showCancel: false

    })

  }

})

  • 预期表现

搜索时周边BLE设备多的时候也能正常回调wx.onBluetoothDeviceFound

  • 复现路径
  • 提供一个最简复现 Demo

 

2 回复

麻烦提供一下日志:我->设置->帮助与反馈右上角有个上报日志的入口
提供一下出现问题的微信号,出现问题的时间点(精确到分钟)

我也遇到了,微信7.0.4,sdk2.6.6,问题初步定位,设置interval是导致闪退的原因,不设置则没问题

回到顶部