如何让蓝牙扬声器在登录时自动连接?

如何让蓝牙扬声器在登录时自动连接?

今天我在预装了 Windows 7 的 Dell Latitude E6410i 上安装了 Ubuntu 18.04 x64 LTS。我连接到我的新JBL Flip4 扬声器使用蓝牙 4.2 和 A2DP V1.3、AVRCP V1.6、HFP V1.6 和 HSP V1.2,并成功配对。

我想在登录时自动连接到扬声器;每次我登录 Ubuntu 时它都应该连接,但却没有。

经过研究,我在网上找到了一些建议(比如在 Ubuntu 16.04 中自动连接到蓝牙扬声器rc.local),但我在系统中找不到。此外,我安装了bt 自动连接 这没有帮助。

我该如何解决这个问题?

答案1

解决方法

注意:
下面的程序已在我的JBL Xtreme
操作系统上测试:Ubuntu 18.04

在你目前的情况下,你已经配对了你的蓝牙设备,并且在启动时你的蓝牙设备处于打开状态,

登录后尝试这个..

  1. 打开终端并运行bluetoothctl

  2. 输出将类似于此

输出:

pratap@i7-4770:~$ bluetoothctl
[NEW] Controller xx:xx:xx:xx:xx:xx i7-4770 [default]
[NEW] Device aa:bb:cc:dd:ee:ff JBL Xtreme
[NEW] Device xx:xx:xx:xx:xx:xx HUAWEI P smart
Agent registered
[bluetooth]# 
  1. 在上述情况下,“JBL Xtreme”蓝牙设备已配对但尚未连接。因此要连接到此设备

connect aa:bb:cc:dd:ee:ff在提示符下运行[bluetooth]#

例子:

[bluetooth]# connect aa:bb:cc:dd:ee:ff
Attempting to connect to aa:bb:cc:dd:ee:ff
[CHG] Device aa:bb:cc:dd:ee:ff Connected: yes
Connection successful
[CHG] Device aa:bb:cc:dd:ee:ff ServicesResolved: yes
[JBL Xtreme]#

这意味着如果您可以运行该命令bluetoothctl,然后在[bluetooth]#提示符下如果您可以输入,connect aa:bb:cc:dd:ee:ff则蓝牙设备将会连接。

因此,这可以通过终端中的单个命令来完成,第一次登录后,打开终端并运行此命令。

echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl

例子:

pratap@i7-4770:~$ echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl
[NEW] Controller xx:xx:xx:xx:xx:xx i7-4770 [default]
[NEW] Device aa:bb:cc:dd:ee:ff JBL Xtreme
[NEW] Device xx:xx:xx:xx:xx:xx HUAWEI P smart
Agent registered
[bluetooth]# connect aa:bb:cc:dd:ee:ff
Attempting to connect to aa:bb:cc:dd:ee:ff
Agent unregistered
[DEL] Controller xx:xx:xx:xx:xx:xx i7-4770 [default]
pratap@i7-4770:~$

因此命令echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl正在起作用..

这意味着如果我们可以在登录时无需人工交互就运行此命令,则在启动时已配对且已打开的蓝牙设备将以上述手动方式连接。


  1. mkdir ~/bin(如果尚未创建,请创建此目录。否则请忽略此步骤)

  2. touch ~/bin/btautoconnect.sh

  3. gedit ~/bin/btautoconnect.sh

粘贴以下内容:

#!/bin/bash

bluetoothctl
sleep 10
echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl
sleep 12
echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl
exit
  1. 保存并关闭文件。

  2. chmod +x ~/bin/btautoconnect.sh

btautoconnect.desktop创建一个名为.desktop 文件~/.config/autostart/

  1. touch ~/.config/autostart/btautoconnect.desktop

使用 gedit 打开文件并将内容复制粘贴到此命令下方

  1. gedit ~/.config/autostart/btautoconnect.desktop

内容:

[Desktop Entry]
Type=Application
Exec=/bin/bash /home/pratap/bin/btautoconnect.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=BTAutoConnect
X-GNOME-Autostart-Delay=5
Comment=Starts Bluetooth speaker
  1. 重新启动即可看到蓝牙设备已连接登录后 10 到 20 秒内..无需任何人工交互..

致谢:https://ubuntuforums.org/showthread.php?t=2365083

答案2

在 Ubuntu 中,声音问题是由于安装了驱动程序造成的。如果这个扬声器是最新、最流行的硬件,那么您就没有机会了,而且必须等待 2 到 8 个月,直到驱动程序出现在 Linux 社区中。但您可以尝试在终端中安装以下软件包:

sudo apt-get 安装 amarok rhythmbox

重启

然后打开蓝牙并查看您的扬声器是否受支持:

  • 打开活动概述并开始输入蓝牙。
  • 单击蓝牙打开面板。
  • 将顶部的开关设置为 ON。

祝你好运,或者耐心最多 8 个月。

相关内容