react-native-ble-manager
react-native-ble-manager copied to clipboard
Android doesn't discover any devices after a small while
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);
- BleManager.start();
- 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
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
Hi, do you find something?
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 ```
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 });
});
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.
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 .
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.