简体   繁体   中英

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. My environment is as below Machine: Ubuntu 12.4, Quad Core, 8GB Ram. 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

It adds support for 64 bit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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