问题
I m developing a ble app that goes out of range many times or turns off, it is designed to do so.
if connected to android if i turn off my Bluetooth low energy (smart) device the Bluetooth manager still keeps that profile for some time and then removes it after calling the onClientConnectionState()
method.
Even the device is visible in the list i get from getConnectedDevices(int)
.
how can i invoke the method device removal from the android device
回答1:
There are two parameters used in ble that describes when to mark a connection as lost:
connection intervall: intervall to communicate at (on other 'ticks' the device 'sleeps') (between 7.5ms - 4s)
connection slave latency: thats the number on how many communications can be omitted without marking the connection lost (between 0-499). After this treshhold is exceeded the connection is marked as lost.
As it is not officially documented how these parameters are set in android you will not know if this is the gap you saw between turning your periheral off and getting the event that it is actually disconnected. Could be between ~7.5ms and ~2000s....
You only can use the notification in onClientConnectionState()
to monitor out-of-range devices.
来源:https://stackoverflow.com/questions/26434202/android-ble-device-status-shows-connected-for-some-seconds-even-after-turning-o