gpt4 book ai didi

javax.bluetooth.BluetoothStateException : BlueCove com. intel.bluetooth.BluetoothStackBlueZ 不可用

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:22:59 29 4
gpt4 key购买 nike

我正在处理 JavaBlueCove 以找到蓝牙设备。

我创建了一个 Maven 项目并添加了 BlueCove 依赖项:

<dependency>
<groupId>net.sf.bluecove</groupId>
<artifactId>bluecove</artifactId>
<version>2.1.0</version>
</dependency>

我在 Ubuntu 上工作,我安装了以下软件包:

sudo apt-get install bluez libbluetooth-dev
sudo apt-get build-dep bluez-tools

我复制并粘贴了一个示例 from here ,基本上如下:

import java.util.Vector;

import javax.bluetooth.DeviceClass;
import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.DiscoveryListener;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.RemoteDevice;
import javax.bluetooth.ServiceRecord;

public class RemoteDeviceDiscovery {

public Vector getDevices() {
/* Create Vector variable */
final Vector devicesDiscovered = new Vector();
try {
final Object inquiryCompletedEvent = new Object();
/* Clear Vector variable */
devicesDiscovered.clear();

/* Create an object of DiscoveryListener */
DiscoveryListener listener = new DiscoveryListener() {

public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
/* Get devices paired with system or in range(Without Pair) */
devicesDiscovered.addElement(btDevice);
}

public void inquiryCompleted(int discType) {
/* Notify thread when inquiry completed */
synchronized (inquiryCompletedEvent) {
inquiryCompletedEvent.notifyAll();
}
}

/* To find service on bluetooth */
public void serviceSearchCompleted(int transID, int respCode) {
}

/* To find service on bluetooth */
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
}
};

synchronized (inquiryCompletedEvent) {
/* Start device discovery */
boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, listener);
if (started) {
System.out.println("wait for device inquiry to complete...");
inquiryCompletedEvent.wait();
}
}
} catch (Exception e) {
e.printStackTrace();
}
/* Return list of devices */
return devicesDiscovered;
}
}

但是当我运行我的程序时出现错误:

javax.bluetooth.BluetoothStateException: BlueCove com.intel.bluetooth.BluetoothStackBlueZ not available

在这一行:

boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, listener);

我已经看到了 similar question 的其他答案没有成功。

有什么想法吗?

最佳答案

好吧,我知道我来晚了,但我在谷歌上搜索了同样的问题。这在 ubuntu 18.04 上对我有用:

sudo apt install blueman libbluetooth* bluez*
sudo systemctl start bluetooth

可以查看蓝牙状态后:

sudo systemctl status bluetooth

希望你能看到这个,如果你看到了,这对你有帮助:)

关于javax.bluetooth.BluetoothStateException : BlueCove com. intel.bluetooth.BluetoothStackBlueZ 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50704036/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com