4
import {BleManager} from 'react-native-ble-plx';

const DeviceManager = new BleManager();

export const scan = function scan() {
    const subscription = DeviceManager.onStateChange((state) => {
        if (state === 'PoweredOn') {
          DeviceManager.startDeviceScan(null, null, (error, device) => {
            if (error) {
              console.log("error",error);
            }
            if (device !== null) {
                console.log("device found ----> [id,name]", device.id, device.name);
            }
          });
          subscription.remove();
        }
    }, true);
}

This is my code to scan for nearby devices. When I run the app, only my laptop is detected although there are other nearby devices (phones that support Bluetooth LE) with Bluetooth turned on.

Also for my laptop, only the device id is shown, and the device name is shown as null.

Is my code missing something to detect all nearby devices and all the data of detected devices?

JayaniH
  • 293
  • 1
  • 2
  • 9

0 Answers0