为了查找蓝牙设备,我正在处理、Java、和BlueCove。
我创建了一个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我复制并粘贴了一个示例从这里开始,基本上如下所示:
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);我已经看到了相似问题的其他答案,但没有成功。
有什么想法吗?
发布于 2019-09-12 14:48:34
好吧,我知道我迟到了,但我也在谷歌上搜索同样的问题。这对我来说很适用于ubuntu 18.04:
sudo apt install blueman libbluetooth* bluez*
sudo systemctl start bluetooth检查蓝牙状态后:
sudo systemctl status bluetooth希望你看到这个,如果你看到了,这会有所帮助:)
https://stackoverflow.com/questions/50704036
复制相似问题