首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-native-ble-manager未显示移动蓝牙和蓝牙耳机

react-native-ble-manager未显示移动蓝牙和蓝牙耳机
EN

Stack Overflow用户
提问于 2021-06-22 14:43:32
回答 1查看 403关注 0票数 0

我正在尝试实现我的应用程序的蓝牙服务。但是当扫描时,我的应用程序没有显示手机蓝牙和蓝牙耳机蓝牙。

仅在控制台中显示没有名称的蓝牙。

请帮我解决这个问题。

代码语言:javascript
复制
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>
    )
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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进行访问。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68078695

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档