这是根据文档写的查找低功耗蓝牙
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协议,还试过其他蓝牙设备,都不行,蓝牙权限也开启了
1***@qq.com
确实如此
2024-07-03 16:57
1***@qq.com
回复 1***@qq.com: 位置权限打开了也没有用
2024-11-08 16:07