Reputation: 33
I am trying to develop a BLE app that has multiple activities to control a custom BLE device. The problem I am having right now is dealing when the device is out of range or when connection is lost.
The app has a BLE service that handles scanning and Gatt connections. After the user has selected a device in the first activity, the second activity launches and the app connects to the selected device. In the second activity the user can choose from 4 different menus, each launches a new activity.
One option is the device control, used to start/stop data acquisition. At any given time if BLE connection is lost, an alert dialog shows up to allow the user to reconnect to the device. However when connection is lost in the third activity ( device control ) upon reconnecting, if I then exit the activity and resume again, the app doesn't update the status anymore.
Sorry I know this is probably very vague, but I really have no idea what is causing this issue. I have narrowed it down to the BLE service, which automatically queues BLE requests ( write, read etc..) and executes them when Gatt isn't busy. And the problem occurs because Gatt never clears the busy flag, after returning from the second activity but I can't figure out why.
Thanks for the help.
Upvotes: 0
Views: 320
Reputation: 33
The issue seems to have been resolved by having a first direct connection via device.connectGatt(contex,false,callback)
then for subsequent connections to be handled by BluetoothGatt.connect()
, as shown in the BluetoothLeGatt example. And also to call BlutoothGatt.disconnect()
before each reconnect attempt so the app doesn't hang on waiting for Gatt connection timeout.
Upvotes: 0