2***@qq.com
2***@qq.com
  • 发布:2020-11-29 10:52
  • 更新:2023-06-08 20:06
  • 阅读:2675

uni-app找不到任何蓝牙设备

分类:uni-app

这是根据文档写的查找低功耗蓝牙

uni.openBluetoothAdapter({  
                    success: function() {  
                        uni.onBluetoothDeviceFound(function(e) {  
                            console.log(e)  
                        })  
                        uni.startBluetoothDevicesDiscovery({  
                            success:function(){  
                                console.log("开始")  
                            }  
                        })  
                        uni.getBluetoothAdapterState({  
                            success: function(e) {  
                                console.log(JSON.stringify(e))  
                            }  
                        })  
                        setInterval(function(){  
                            uni.getBluetoothDevices({  
                                success:function(e){  
                                    console.log(JSON.stringify(e))  
                                }  
                            })  
                        },1000)  
                    }  
                })

这是官方的其他蓝牙

var main, BAdapter, BluetoothAdapter, BluetoothDevice;  
                main = plus.android.runtimeMainActivity();  
                BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");  
                BAdapter = BluetoothAdapter.getDefaultAdapter();  
                BluetoothDevice = plus.android.importClass('android.bluetooth.BluetoothDevice');  
                BAdapter.startDiscovery()  
                console.log("start")  
                var foundreceiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {  
                    onReceive: function(context, intent) {  
                        console.log("查找到设备")  
                        plus.android.importClass(intent);  
                        var BleDevice = new BluetoothDevice();  
                        BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);  
                        console.log("蓝牙设备:" + BleDevice.getName() + BleDevice.getAddress());  
                    }  
                });  

                //注册接收器    
                var IntentFilterScan = plus.android.importClass('android.content.IntentFilter');  
                var filterScan = new IntentFilterScan();  
                filterScan.addAction(BluetoothDevice.ACTION_FOUND); //搜索设备                      
                main.registerReceiver(foundreceiver, filterScan); //注册监听

蓝牙模块用的是HC-05,支持ble协议,还试过其他蓝牙设备,都不行,蓝牙权限也开启了

2020-11-29 10:52 负责人:无 分享
已邀请:
biorhythm

biorhythm - 上海节律生物科技有限公司

部分安卓系统中需要打开位置权限才能发现外设的广播

  • 1***@qq.com

    确实如此

    2024-07-03 16:57

  • 1***@qq.com

    回复 1***@qq.com: 位置权限打开了也没有用

    2024-11-08 16:07

要回复问题请先登录注册