简体   繁体   English

通过Java代码连接到蓝牙设备

[英]Connect to Bluetooth Device via Java Code

I want to connect to another bluetooth device through my laptop's bluetooth. 我想通过笔记本电脑的蓝牙连接到另一个蓝牙设备。

I'm using bluecove library for my reference. 我正在使用bluecove库作为参考。 My environment is as below Machine: Ubuntu 12.4, Quad Core, 8GB Ram. 我的环境如下计算机:Ubuntu 12.4,四核,8GB Ram。 Java: 1.8 Blueove: bluecove-2.1.1-SNAPSHOT.jar, bluecove-gpl-2.1.0.jar Java:1.8 Blueove:bluecove-2.1.1-SNAPSHOT.jar,bluecove-gpl-2.1.0.jar

I have written below code to connect to the local bluetooth device. 我已经编写了以下代码以连接到本地蓝牙设备。

   LocalDevice localDevice = LocalDevice.getLocalDevice();
        DiscoveryAgent agent = localDevice.getDiscoveryAgent();
        agent.startInquiry(DiscoveryAgent.GIAC, listener);

But Im getting below error when I execute this code. 但是我执行此代码时,我遇到了错误。

Native Library bluecove not available
javax.bluetooth.BluetoothStateException: BlueCove library bluecove not available;
resource not found libbluecove.so
load [bluecove] no bluecove in java.library.path
    at com.intel.bluetooth.BlueCoveImpl.loadNativeLibraries(BlueCoveImpl.java:396)
    at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:450)
    at com.intel.bluetooth.BlueCoveImpl.access$500(BlueCoveImpl.java:69)
    at com.intel.bluetooth.BlueCoveImpl$1.run(BlueCoveImpl.java:1044)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1042)
    at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1035)
    at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
    at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
    at bt.MyDiscoveryListener.main(MyDiscoveryListener.java:36)

Kindly help me out to get rid this of error. 请帮助我摆脱这种错误。 I have also tried with building native library but it didn't help. 我也尝试过构建本机库,但没有帮助。

I appreciate all your answers. 感谢您的回答。 Thanks. 谢谢。

尝试像这样启动您的JRE: java.exe -Djava.library.path=your_path_to_libbluecove.so ...other options...这至少应该解决“找不到资源”的问题。

If you use this never released snapshot of BlueCove: BlueCove 2.1.2 如果您使用从未发布过的BlueCove快照: BlueCove 2.1.2

It adds support for 64 bit 它增加了对64位的支持

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM