Alessandro
Alessandro

Reputation: 4472

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

I'm dealing with Java and BlueCove in order to find the bluetooth devices.

I've created a Maven Project and I've added the BlueCove dependency:

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

I'm working on Ubuntu, I've installed the following packages:

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

I've copied and pasted an example from here, basically the following:

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;
    }
}

But when I run my program I get the error:

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

at this line:

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

I've already seen other answers to a similar question with no success.

Any idea?

Upvotes: 3

Views: 1159

Answers (1)

Fede
Fede

Reputation: 340

Ok, I know I'm super late, but I was googling the same problem. This worked for me on ubuntu 18.04:

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

After you can check the bluetooth status:

sudo systemctl status bluetooth

Hope you see this, and if you do, that this helped :)

Upvotes: 1

Related Questions