I have installed bluecove by adding those two library in IntellJ:
bluecove-2.0.2.jar
and
bluecove-gpl-2.1.0.jar
and I ran the sample code provided in bluecove:
import java.io.IOException;
import java.util.Vector;
import javax.bluetooth.*;
/**
* Minimal Device Discovery example.
*/
public class RemoteDeviceDiscovery {
public static final Vector/*<RemoteDevice>*/ devicesDiscovered = new Vector();
public static void main(String[] args) throws IOException, InterruptedException {
final Object inquiryCompletedEvent = new Object();
devicesDiscovered.clear();
DiscoveryListener listener = new DiscoveryListener() {
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
System.out.println("Device " + btDevice.getBluetoothAddress() + " found");
devicesDiscovered.addElement(btDevice);
try {
System.out.println(" name " + btDevice.getFriendlyName(false));
} catch (IOException cantGetDeviceName) {
}
}
public void inquiryCompleted(int discType) {
System.out.println("Device Inquiry completed!");
synchronized(inquiryCompletedEvent){
inquiryCompletedEvent.notifyAll();
}
}
public void serviceSearchCompleted(int transID, int respCode) {
}
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
}
};
synchronized(inquiryCompletedEvent) {
boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, listener);
if (started) {
System.out.println("wait for device inquiry to complete...");
inquiryCompletedEvent.wait();
System.out.println(devicesDiscovered.size() + " device(s) found");
}
}
}
}
I got the following stack error:
OpenJDK 64-Bit Server VM warning: You have loaded library
/tmp/bluecove_androidweardev_0/libbluecove.so which might have
disabled stack guard. The VM will try to fix the stack guard now.
It's highly recommended that you fix the library with 'execstack -c
<libfile>', or link it with '-z noexecstack'.
Native Library bluecove not available
Exception in thread "main" javax.bluetooth.BluetoothStateException: BlueCove not available
at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:271)
at com.intel.bluetooth.BlueCoveImpl.access$100(BlueCoveImpl.java:64)
at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:502)
at java.security.AccessController.doPrivileged(Native Method)
at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:500)
at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:489)
at javax.bluetooth.LocalDevice.<init>(LocalDevice.java:64)
at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:71)
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:86)
at RemoteDeviceDiscovery.main(RemoteDeviceDiscovery.java:44)
I've installed libbluetooth-dev, blueman and bluez but none seem to make it work, I'm out of options.
I' m also looking if there a bluetooth SIG official example using bluetooth-low energy with java.
Any advice or tip is appreciated thanks.