Android scan does not discover any peripherals
See original GitHub issueVersion
Tell us which versions you are using:
- react-native-ble-manager v6.6.6
- react-native v59.9
- Android v.8.1.0 on Nexus 6P phone
Expected behaviour
Would expect to see one or more Bluetooth peripherals to be discovered.
Actual behaviour
No peripherals are found whatsoever on Android Nexus 6P with Android 8.1.0. (Note that the ‘stopScan’ event does get triggered after the expected 5 seconds)
Works fine on iOS and on Android-based Kindle Fire HD10 7th generation.
Steps to reproduce
import React from 'react'
import { NativeModules, NativeEventEmitter } from 'react-native'
import BleManager from 'react-native-ble-manager'
const eventEmitter = new NativeEventEmitter(NativeModules.BleManager)
export default class App extends React.Component {
async componentDidMount() {
eventEmitter.addListener(
'BleManagerDiscoverPeripheral',
async (args) => {
console.log("found: " + args.id)
}
)
eventEmitter.addListener(
'BleManagerStopScan',
() => {
console.log("done")
}
)
console.log("started")
await BleManager.start( { forceLegacy: true } )
console.log("scanning")
await BleManager.scan([], 5)
}
render() {
return null
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Bluetooth LE Scanning Sometimes Doesn't Find Devices
I have a companion iOS device running similar code (both scanning for peripherals and acting as a peripheral), and when the Android scanning...
Read more >Find BLE devices - Android Developers
To scan for only specific types of peripherals, you can instead call startScan(List<ScanFilter>, ScanSettings, ScanCallback) , providing a list ...
Read more >Bluetooth peripheral device is not scannable by new Android ...
We discovered that if scan response is padded with 0, Android wont be able to parse it correctly. In other words, make sure...
Read more >DA14683: iOS BLE scan cannot find advertising peripheral ...
Everything works correctly on Android. Android devices are able to scan and find the device and see the DA14683 peripheral advertisements ...
Read more >Find & set up devices near you - Android Help
You can find and set up some devices close to you using your Android phone. ... other Android phones and tablets, or accessories...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Found the problem! 😃
I had missed the Note in the manual stating: “Android API >= 23 require the ACCESS_COARSE_LOCATION permission to scan for peripherals”. (and apparently, a lack of permissions does not cause the ‘scan’ method to trow an exception).
Here’s updated code with the fix:
@rayjadore the
scan
method just starts the scan. It doesn’t return anything (other than a promise). I would expect your code to returnundefined
on iOS also.Use the
BleManagerDiscoverPeripheral
event to report peripherals found. Also, make sure to callBleManager.start({ forceLegacy: true })
first.If it still doesn’t work, then perhaps we face the same problem.