uni-app中uni.openBluetoothAdapter没有回调
uni-app中uni.openBluetoothAdapter没有回调
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Mac | 10.15.0 | CLI |
| Android | Android 10 | - |
| 小米 | - | - |
| 小米 10 | - | - |
### 示例代码:
```javascript
openBluetoothAdapter() {
let me = this;
console.log("openBluetoothAdapter")
uni.openBluetoothAdapter({
success(res){
// 状态正常
console.log("success",res)
},
fail(res) {
},
complete(res) {
console.log("初始化蓝牙模块-openBluetoothAdapter", res)
},
})
},
操作步骤:
onLoad(options){
this.openBluetoothAdapter()
},
methods:{
// 打开蓝牙适配器
openBluetoothAdapter() {
let me = this;
console.log("openBluetoothAdapter")
uni.openBluetoothAdapter({
success(res){
// 状态正常
console.log("success",res)
},
fail(res) {
},
complete(res) {
console.log("初始化蓝牙模块-openBluetoothAdapter", res)
},
})
},
}
预期结果:
打印成功回调结果
实际结果:
没有回调
bug描述:
项目运行在手机调试时,打开手机蓝牙后uni.openBluetoothAdapter没有任何的回调
更多关于uni-app中uni.openBluetoothAdapter没有回调的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于uni-app中uni.openBluetoothAdapter没有回调的实战教程也可以访问 https://www.itying.com/category-93-b0.html
根据你提供的信息,uni.openBluetoothAdapter 没有回调,这通常与权限配置或设备兼容性有关。以下是排查步骤:
-
检查 Android 权限配置
在manifest.json中确保已添加蓝牙权限:"permissions": { "android": { "permissions": [ "android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN", "android.permission.ACCESS_FINE_LOCATION" ] } }Android 6.0+ 需要动态申请定位权限才能使用蓝牙,需在调用
openBluetoothAdapter前通过uni.authorize申请scope.location。 -
确认系统蓝牙已开启
代码中未检查蓝牙状态,建议先调用uni.getSystemInfo或监听uni.onBluetoothAdapterStateChange确保蓝牙可用。 -
真机调试日志
在fail回调中添加console.log捕获错误,例如:fail(res) { console.error('openBluetoothAdapter fail:', res) }

