0

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?

sschrass
  • 7,014
  • 6
  • 43
  • 62
Sharath S
  • 9
  • 2

2 Answers2

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.

What triggers the BluetoothDevice.ACTION_ACL broadcasts?

Community
  • 1
  • 1
aiden_fry
  • 304
  • 3
  • 9
  • 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