我已经通过在IntellJ中添加这两个库来安装bluecove:
bluecove-2.0.2.jar和bluecove-gpl-2.1.0.jar
我运行了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");
}
}
}
}我得到了下面的堆栈错误:
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)我已经安装了libbluetooth-dev,blueman和bluez,但似乎都不能正常工作,我别无选择。
我也在寻找是否有一个使用蓝牙的蓝牙SIG官方示例-使用java的低能耗。
任何建议或提示都是感谢的。
发布于 2018-04-19 21:45:08
我想出来了,主要的问题是bluecove-2.0.2.jar和bluecove-gpl-2.1.0.jar版本不匹配。
我将bluecove-2.0.2.jar替换为bluecove-2.1.0.jar。
现在一切都正常了。
https://stackoverflow.com/questions/49906318
复制相似问题