react-native-ble-manager icon indicating copy to clipboard operation
react-native-ble-manager copied to clipboard

Android doesn't discover any devices after a small while

Open wesdewitte opened this issue 5 years ago • 7 comments

Version

Tell us which versions you are using:

  • react-native-ble-manager v6.6.2
  • react-native v0.59.5
  • Android 8.1.0

Expected behaviour

Im scanning for 10 seconds long every 50 seconds. it should scan devices.

Actual behaviour

it scans devices till about the 5th time around that time. Then it doesn't receive any devices anymore. Situation doesn't change is the meanwhile. The handleDiscoverPeripheral listener doesn't get any devices anymore.

Steps to reproduce

// Bluetooth Manager import BleManager from 'react-native-ble-manager'; BleManagerModule = NativeModules.BleManager; bleManagerEmitter = new NativeEventEmitter(BleManagerModule);

  1. BleManager.start();
  2. scan 10 seconds long for every 50 seconds BleManager.scan([], 10, false) 3.bleManagerEmitter.addListener('BleManagerDiscoverPeripheral', this.handleDiscoverPeripheral );

Logs

This is the point it doesn't scan devices anymore and the stopped listener gets called twice which is weird.

Info - 🔵 BluetoothManager Function: __scanBleAndroid Start scanning Info - 🔵 BluetoothManager Function: handleStopScan Stopped scanning Debug - 🔵 BluetoothManager Function: handleScannedBluetoohDevices Debug - 🔵 BluetoothManager Function: handleScannedBluetoohDevices no devices scanned Info - 🔵 BluetoothManager Function: handleStopScan Stopped scanning Debug - 🔵 BluetoothManager Function: handleScannedBluetoohDevices Debug - 🔵 BluetoothManager Function: handleScannedBluetoohDevices no devices scanned

wesdewitte avatar May 02 '19 07:05 wesdewitte

In the logs i came across this :

2019-05-02 10:54:48.074 D/BluetoothLeScanner: Start Scan with callback 2019-05-02 10:54:48.077 D/BluetoothLeScanner: onScannerRegistered() - status=133 scannerId=0 mScannerId=0 2019-05-02 10:54:48.077 D/BluetoothLeScanner: Registration failed, unregister scannerId = 0 2019-05-02 10:54:48.077 D/BluetoothLeScanner: Scan failed, reason: app registration failed

wesdewitte avatar May 02 '19 08:05 wesdewitte

Hi, do you find something?

marcosinigaglia avatar Jun 18 '19 10:06 marcosinigaglia

I think android is blocking the scanning so it returns no devices

2019-06-25 12:03:14.766 4333-4807/? W/BtGatt.ScanManager: Cannot start unfiltered scan in screen-off. This scan will be resumed later: 8
2019-06-25 12:04:05.633 4333-4807/? W/BtGatt.ScanManager: Cannot start unfiltered scan in screen-off. This scan will be resumed later: 8
2019-06-25 12:05:37.789 4333-4807/? W/BtGatt.ScanManager: Cannot start unfiltered scan in screen-off. This scan will be resumed later: 8
2019-06-25 12:07:00.289 4333-4807/? W/BtGatt.ScanManager: Cannot start unfiltered scan in screen-off. This scan will be resumed later: 8 ```

wesdewitte avatar Jun 25 '19 10:06 wesdewitte

Just extend the time of searching. In my case i extend time from 3 second to 5 and it is searching approximately all the available

BleManager.scan([], 5, true).then((results) => {
                console.log('Scanning...');
                this.alreadySent = []
                this.setState({ scanning: true, show: false });
            });

Hassam34 avatar Dec 23 '19 11:12 Hassam34

Hi, I am experiencing the same problem on Android 10. I could not solve the problem, so I am using a workaround.

In my use case the user is supposed to know the peripheral to which the application should connect: as a consequence, he/she should leave the application and manually pair the peripheral.

At this point, the peripheral will be available using BleManager.getBondedPeripherals([])

Looking forward to find a final solution.

fbambusi avatar May 17 '20 13:05 fbambusi

This package is not working one. This is not right choice to use this package for bluetooth tasks with react native . Don't run for this , there are more other pacakges all of you can use .

joy-mollick avatar Sep 16 '21 23:09 joy-mollick

Hi @joy-mollick , I don't think your comment is useful, the library is working in many situations, if you find a bug you can solve it and make a PR.

marcosinigaglia avatar Sep 17 '21 08:09 marcosinigaglia