Android 上是否可以检测到用户关闭蓝牙?
在我的 Android 应用程序中,用户可以使用他的 Android 手机通过另一台设备的蓝牙进行固件更新。
我的问题是:是否可以检测用户何时尝试关闭蓝牙并向他发送警告消息,例如:“警告关闭蓝牙将中断固件更新!”
使用蓝牙适配器广播操作:
公共静态最终字符串ACTION_STATE_CHANGED
自:API 级别 5 广播操作:本地蓝牙的状态 适配器已更改。例如,蓝牙已打开或 离开。始终包含额外字段 EXTRA_STATE 和 EXTRA_PREVIOUS_STATE 包含新旧状态 分别。需要蓝牙才能接收。
常量值:“android.bluetooth.adapter.action.STATE_CHANGED”
只有在蓝牙关闭后才能接收广播(因此警告为时已晚^^)
任何帮助将不胜感激! 此致
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在固件更新开始时显示此类关键消息。此后,如果用户关闭蓝牙,则由他负责。他不能将任何损失归咎于您的软件。
而且我认为我们不被允许阻止诸如关闭蓝牙之类的操作。允许此类阻止将使其容易受到黑客攻击。恶意应用程序可能会阻止用户关闭蓝牙。
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.