我正在尝试实现我的应用程序的蓝牙服务。但是当扫描时,我的应用程序没有显示手机蓝牙和蓝牙耳机蓝牙。
仅在控制台中显示没有名称的蓝牙。
请帮我解决这个问题。
import React, { Component } from 'react';
import { NativeModules, NativeEventEmitter, View, Text } from 'react-native';
import BleManager from 'react-native-ble-manager';
const BleManagerModule = NativeModules.BleManager;
const bleManagerEmitter = new NativeEventEmitter(BleManagerModule);
export default class App extends Component{
state = {
peripherals: new Map(),
};
componentDidMount() {
BleManager.start({ showAlert: false })
this.handlerDiscover = bleManagerEmitter.addListener(
'BleManagerDiscoverPeripheral',
this.handleDiscoverPeripheral
);
this.handlerStop = bleManagerEmitter.addListener(
'BleManagerStopScan',
this.handleStopScan
);
this.scanForDevices(); // I chose to start scanning for devices here
}
scanForDevices() {
BleManager.scan([], 30);
}
handleDiscoverPeripheral = (peripheral) => {
console.log('Got ble peripheral', peripheral);
const { peripherals } = this.state;
if (peripheral.name) {
peripherals.set(peripheral.id, peripheral.name);
}
this.setState({ peripherals });
};
handleStopScan = () => {
console.log('Scan is stopped. Devices: ', this.state.peripherals);
}
render(){
return(
<View>
<Text>Bluetooth</Text>
</View>
)
}
}发布于 2021-06-22 15:34:32
react-native-ble-manager支持您的手机和蓝牙低功耗(BLE)设备之间的通信。BLE设备需要通告它们的存在才能被检测。请记住,BLE与Bluetooth Classic不同。
您只能使用react-native-ble-manager检测BLE设备。如果你找不到你的设备,它们可能不是BLE设备,而是蓝牙经典设备。其他手机通常不宣传BLE服务,需要一个应用程序才能做到这一点。蓝牙耳机可能会使用BLE来实现某些功能,但音频传输是通过蓝牙Classic来处理的。
您可以使用通用的BLE扫描仪应用程序,如nRF Connect来扫描附近的BLE设备。这个应用程序甚至允许你在另一部手机上启动GATT服务器,以便可以使用BLE进行访问。
https://stackoverflow.com/questions/68078695
复制相似问题