Search code examples
androidbluetoothdetection

Is it possible to detect that the user will turn off the Bluetooth on Android?


In my android app, the user has the possibility to do a firmware update via bluetooth of another device with his android phone.

My question is : Is it possible to detect when the user try to turn off the bluetooth and to send him a warning message like :"Warning turning off the bluetooth will interupt the firmware update !"

With the BluetoothAdapter Broadcast Action :

public static final String ACTION_STATE_CHANGED

Since: API Level 5 Broadcast Action: The state of the local Bluetooth adapter has been changed. For example, Bluetooth has been turned on or off. Always contains the extra fields EXTRA_STATE and EXTRA_PREVIOUS_STATE containing the new and old states respectively. Requires BLUETOOTH to receive.
Constant Value: "android.bluetooth.adapter.action.STATE_CHANGED"

It's only possible to receive a broadcast once the Bluetooth is already turned off (so it's too late for the warning ^^ )

Any help would be appreciate ! Best regards


Solution

  • You should show such critical messages at the start of the firmware update. After that if the user switches off the bluetooth then its his responsibility. He cannot blame your software for any loss.

    And I dont think we are allowed to block operations such as turning off bluetooth. Allowing such blocking will make it open to hacks. A malicious app could stop the user from switching off his bluetooth.