2

We have developed an Android app that tracks vehicle journeys, where each vehicle has a BLE device installed that wakes up when the vehicle is started.

To identify when the user is in the vehicle and when we should start tracking their journey, the Android app implements a foreground service that runs a BLE scan (via Android's BluetoothLeScanner) to look for the BLE device. On finding the device (after it wakes up) the scan is stopped and the app will connect to it and retain its connection until the journey ends.

This works well on most Android devices however we are seeing an intermittent issue where the BLE scanner doesn't find the BLE device for minutes after it wakes up. Sometime as much as 5 minutes.

The BLE scanner is configured as follows:

  • Scan Mode = Low Latency
  • Match Mode = Sticky
  • Callback Type = All Matches
  • Report Delay = not set
  • Scan Filter = a device address is set to look for a specific address

We have also implemented a wake lock to ensure the scanning process continues even when the app isn't in the foreground.

We have experienced the delay on some Android 10 devices.

The app targets Android 10.

Any help would be greatly appreciated.

Cheers, Andy

  • Can't you just initially pair to it once (when app is set up for the first time), then just having a pending connect to it forever (connectGatt with autoConnect = true)? Then you won't get any issues with that scanning is slow. – Emil Dec 14 '20 at 00:31
  • Thanks for the suggestion Emil. As part of our business logic the BLE device auto detects when the vehicle is stationary (idle of X minutes) and will disconnect from the phone. This indicates a vehicle journey end. The BLE device will then go to sleep after 20 seconds until re-woken by movement (e.g. the engine switching on). If we do an immediate automatic reconnect this will keep the device awake in this scenario. Do you know if it's possible to defer the autoConnect? Thanks, Andy – user2060819 Dec 14 '20 at 07:42
  • As long as you call connectGatt with autoConnect true when the app is started, Android will forever try to connect or reconnect to the device, even after the device itself disconnects. This is a very simple way to keep connectivity. – Emil Dec 14 '20 at 10:37
  • Bare in mind that from Android 7, an app can only start BLE scan up to 5 times per 30 seconds, but it cannot scan continusouly. Please check this answer for more infos: https://stackoverflow.com/a/63616561/2068732 – matdev Jan 14 '21 at 14:58

0 Answers0