Android手机 蓝牙发现不了设备
发布于 5 年前 作者 xiulancai 19043 次浏览 来自 问答

使用android调试,搜索不到设备,一直都不会执行onBluetoothDeviceFound的回调openBluetoothAdapter执行成功了,startBluetoothDevicesDiscovery也执行成功了,微信的全部权限都打开了,也重启手机了,都不行。代码:

onLoad: function (options) {

       var page = this;

       wx.openBluetoothAdapter({

           success: function (res) {

               wx.onBluetoothAdapterStateChange(function (res) {

                   console.log(`adapterState changed, now is`, res)

               })

           },

           fail: function (res) {

           }

       });

       wx.onBluetoothDeviceFound(devices => {

           console.log(‘new device list has founded’, devices);

       });

       wx.startBluetoothDevicesDiscovery({

           services: [],

           success: function (res) {

               console.log('startBluetoothDevicesDiscovery: success => ', res);

           },

           fail: function (res) {

               console.log('fail => ', res)

           }

       });

   },

4 回复

代码要放在openBluetoothAdaptersuccess 回调去startBluetoothDevicesDiscovery才行吧?

openBluetoothAdapter是异步的,然后你按顺序写,会导致openBluetoothAdapter未成功,就先调用了startBluetoothDevicesDiscovery,导致扫描失败

 是不是微信的蓝牙功能,不完善哟

定位打开了么?有的需要打开定位。

同样问题,就扫描到一次,其余都没有扫描到设备。蓝牙信息discovering始终都是false

回到顶部