-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scanning in background in Android should use a Pending Intent #699
Comments
Hi @omercnet Quick question... when you are launching a scan here... are you filtering by a service UUID? Or running an open scan (i.e., no filters)? I ask because I noticed this line in the startScan doco when looking at your pending intents patch:
Pending intents are only needed when the application process itself may be terminated or paused by the OS and should be relaunched when a device is found. However... this approach doesn't work in general for capacitor applications, as modern Android generally doesn't allow a new Activity like the capacitor browser to be launched from a pending intent like this. I'll run a few more tests with your patch just to confirm my findings here. |
On an Nokia 3.1 Plus with Android 10, I'm seeing that the normal callback scan continues reporting devices in the background once the screen is off. Here's the code I'm using: await BleClient.initialize();
await BleClient.requestLEScan({
services: [numberToUUID(0x180a)],
allowDuplicates: true
}, d => console.log(Date.now(), "device detected", d)) I've got a simulated peripheral (another phone using nrf Connect ) configured with an advertising packet with the I'm seeing that when the screen is off, the updates slow down to a burst every 10s or so... but... the scanning continues to function. Are you able to provide more specifics about the BLE plugin calls you're making here @omercnet , and the operating environment? (Android phone manufacturer... android version... test conditions, etc.)? |
Also relates to #643 |
Describe the bug
The current implementation does not allow connecting to BLE device after the app is backgrounrded
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The app should find the device in the background
Screenshots
If applicable, add screenshots to help explain your problem.
Plugin version:
Additional context
https://developer.android.com/develop/connectivity/bluetooth/ble/background
In android, to receive scan results in the background, the startScan method should be called with a Pending Intent and not a ScanResult
See https://github.com/android/platform-samples/blob/main/samples/connectivity/bluetooth/ble/src/main/java/com/example/platform/connectivity/bluetooth/ble/BLEScanIntentSample.kt#L114-L120 for an official example
The text was updated successfully, but these errors were encountered: