Android 上是否可以检测到用户关闭蓝牙?

发布于 2024-12-04 02:04:16 字数 453 浏览 1 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋千易 2024-12-11 02:04:16

您应该在固件更新开始时显示此类关键消息。此后,如果用户关闭蓝牙,则由他负责。他不能将任何损失归咎于您的软件。

而且我认为我们不被允许阻止诸如关闭蓝牙之类的操作。允许此类阻止将使其容易受到黑客攻击。恶意应用程序可能会阻止用户关闭蓝牙。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文