【问题标题】:react-native-ble-manager is not showing Mobile Bluetooth and BLUETOOTH EARPHONESreact-native-ble-manager 没有显示移动蓝牙和蓝牙耳机
【发布时间】:2021-06-23 06:00:58
【问题描述】:

我正在尝试在我的应用程序中实现蓝牙服务。但是当扫描时盯着我的应用程序到那个时候没有显示移动蓝牙和蓝牙耳机。

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

请帮助解决这个问题。

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>
    )
  }
}

【问题讨论】:

    标签: react-native bluetooth bluetooth-lowenergy


    【解决方案1】:

    react-native-ble-manager 支持您的手机和低功耗蓝牙 (BLE) 设备之间的通信。 BLE 设备需要宣传它们的存在才能被检测到。请记住,BLE 与经典蓝牙不同。

    您只能使用react-native-ble-manager 检测 BLE 设备。如果您找不到您的设备,它们可能根本不是 BLE 设备,而是蓝牙经典设备。其他手机通常不宣传 BLE 服务,需要一个应用程序来宣传。蓝牙耳机可能会使用 BLE 来实现某些功能,但音频传输由蓝牙经典处理。

    您可以使用通用 BLE 扫描仪应用(例如 nRF Connect)扫描附近的 BLE 设备。该应用程序甚至允许您在另一部手机上启动 GATT 服务器,以便使用 BLE 访问它。

    【讨论】:

    • 我也在使用 react-native-ble-manager 并且遇到同样的问题,扫描有时找到,有时找不到我的 BLE 设备。始终可以找到应用程序 nRF Connect 上的 BLE 扫描仪。你有解决这个问题的办法吗?
    • @cảnhnguyễn 请打开一个新问题并提供尽可能多的信息
    • 我在我的手机设备上扫描蓝牙,看不到,但在应用程序 nRF Connect 上的 BLE 扫描仪上扫描总是找到。
    • @cảnhnguyễn 正如我所说,请打开一个新问题。用不同的问题评论现有问题并不能得到答案
    猜你喜欢
    • 2020-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多