I am developing an Android application that uses Bluetooth Low Energy to receive data from a peripheral device. The device itself sends data as part of an advertising message, and it can send a message at any time. In this way, applications work by continuously scanning BLE devices. When the screen is turned on, the application receives the scan results as intended. When the screen is off, it shows that it receives scan results every 5 seconds. I assume the phone is trying to optimize battery life, but this application is critical, so we cannot afford to lose messages.
Scanning is performed by a service that installs as a "foreground service", so the OS knows that this is important. The service also receives PowerManager.PARTIAL_WAKE_LOCK, but this does not seem to help. The application is excluded from battery optimization, so it does not go into Doze mode or in deep sleep mode. The application uses the following ScanSettings:
ScanSettings.SCAN_MODE_LOW_LATENCY
ScanSettings.CALLBACK_TYPE_ALL_MATCHES
ScanSettings.MATCH_MODE_AGGRESSIVE
ScanSettings.MATCH_NUM_MAX_ADVERTISEMENT
I work with the Galaxy S7, but I was told that the same behavior happens with the Galaxy S7 Edge. I tested with devices other than samsung, and they work as intended (continuously receiving scan results when the screen is off).
Question : is there something that I, as a developer, can make the BT adapter deliver scan results continuously, even when the screen is off?