为了找到蓝牙设备,我正在处理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

我复制并粘贴了一个示例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);

我已经看到了对asimilar question的其他回答,但没有成功。
知道吗?

最佳答案

好吧,我知道我迟到了,但我也在搜索同样的问题。
这对我在Ubuntu18.04上很有效:

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

检查蓝牙状态后:
sudo systemctl status bluetooth

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

10-08 14:26