我使用的蓝牙耳机采用蓝牙4.1版本。当我连接 Android 时,它会显示电池状态。但在 Linux (Ubuntu 18.04) 中我无法获取电池状态。我尝试使用
bluetoothctl
,像其他问题一样在 /sys/class/power_supply
中查找文件,但他们没有帮助我。
askubuntu.com/questions/53880/有什么方法可以检查苹果无线外设的电池百分比
stackoverflow.com/questions/49078659/check-battery-level-of-connected-bluetooth-device-on-linux
我的蓝牙设备不使用 GATT 配置文件。它使用 A2DP 接收器来传输音频。
我查看了 Bluez 文档。他们都说是使用 GATT 配置文件并获取属性。
有没有办法在 Linux 中正确读取电池状态? Android设备如何获取电池状态?这是 Linux 蓝牙堆栈的弱点吗?
自从 Dmitry Sharshakov 提出此拉取请求以来,PipeWire 支持报告电池状态(对于使用 Apple HFP AT 命令的设备)。它使用 bluez 的 Battery Provider API,该 API 仍处于实验阶段,仅当使用 bluetoothd
标志启动
-E
时才可用。在 Arch Linux 上,应该足够运行了
cp /usr/lib/systemd/system/bluetooth.service /etc/systemd/system/
sed -i -r 's/ExecStart=.+/& -E/' /etc/systemd/system/bluetooth.service
systemctl daemon-reload
systemctl restart bluetooth
并且应该会出现耳机电池电量。要以编程方式获取电池电量,您可以使用 UPower 的 DBus API。
注意
记得在 sudo 或 doas 或 root 模式下编辑文件。
/etc/bluetooth/main.conf
。
# Experimental = false
Experimental = true
,并记住删除该行的
#
符号,使其成为命令而不是注释。
sudo systemctl restart bluetooth