I want a set of statements to be executed just before bluetooth turns off manually or before a connection is closed when user goes out of range. Which functions to use / how to do it?
Asked
Active
Viewed 39 times
2 Answers
1
You implement a BroadcastReceiver
which listens for ACTION_STATE_CHANGED
. In the onReceive
method of your BroadcastReceiver
, you put the set of statements you want to execute. See this.

Eric B.
- 4,622
- 2
- 18
- 33
-
thanks for answering, I have to send reset command from mobile to another device just before bluetooth gets disconnected manually (switch off bluetooth) or by range(user goes out of range). The statements has to be executed just before disconnection. As it cannot be done, i will look for alternative. – Sharath S Dec 23 '15 at 10:22
0
There is no "Just Before" a Bluetooth connection drops or the state is change. Android will tell you when it drops, becomes inactive or is turned off.
Have a look at this page, because you can listen to ACL_BLUETOOTH_DISCONNECTED - similar to ACTION_STATE_CHANGED, but be aware of the functionality it contains as it is not quite what I expected.
-
thanks for answering, I have to send reset command from mobile to another device just before bluetooth gets disconnected manually (switch off bluetooth) or by range(user goes out of range). The statements has to be executed just before disconnection. As it cannot be done, i will look for alternative. – Sharath S Dec 23 '15 at 10:23