How To Detect Bluetooth Changes (connection State And Characteristic) When App Is In Background Without A Foreground Service
I have a device that is a simple BLE device with a button, and I need to detect when the user long presses the device (via characteristic change) even when the app is in the backgr
Solution 1:
1: Yes you can achieve this without using a foreground service, by using a JobIntentService.
This type of service does not require to display a notification to your user.
To know when the device button has been clicked, your JobIntentService could scan for BLE devices, and you could include in the BLE data advertised by your device a flag or timestamp of the last click.
In order to avoid draining the battery, I suggest you don't scan continuously, but only for a few seconds every minute.
2: If your BLE scanner receives BLE data advertised by the device, it means the device is within range.
Post a Comment for "How To Detect Bluetooth Changes (connection State And Characteristic) When App Is In Background Without A Foreground Service"