java 蓝牙设备发现错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16886146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error in Bluetooth Device Discovery
提问by Ranveer
I tried the following code for discovering a bluetooth device
我尝试了以下代码来发现蓝牙设备
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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;
import javax.bluetooth.UUID;
/**
*
* Class that discovers all bluetooth devices in the neighbourhood,
*
* Connects to the chosen device and checks for the presence of OBEX push service in it.
* and displays their name and bluetooth address.
*
*
*/
public class BluetoothServiceDiscovery implements DiscoveryListener{
//object used for waiting
private static Object lock=new Object();
//vector containing the devices discovered
private static Vector vecDevices=new Vector();
private static String connectionURL=null;
/**
* Entry point.
*/
public static void main(String[] args) throws IOException {
BluetoothServiceDiscovery bluetoothServiceDiscovery=new BluetoothServiceDiscovery();
//display local device address and name
LocalDevice localDevice = LocalDevice.getLocalDevice();
System.out.println("Address: "+localDevice.getBluetoothAddress());
System.out.println("Name: "+localDevice.getFriendlyName());
//find devices
DiscoveryAgent agent = localDevice.getDiscoveryAgent();
System.out.println("Starting device inquiry...");
agent.startInquiry(DiscoveryAgent.GIAC, bluetoothServiceDiscovery);
try {
synchronized(lock){
lock.wait();
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Device Inquiry Completed. ");
//print all devices in vecDevices
int deviceCount=vecDevices.size();
if(deviceCount <= 0){
System.out.println("No Devices Found .");
}
else{
//print bluetooth device addresses and names in the format [ No. address (name) ]
System.out.println("Bluetooth Devices: ");
for (int i = 0; i <deviceCount; i++) {
RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(i);
System.out.println((i+1)+". "+remoteDevice.getBluetoothAddress()+" ("+remoteDevice.getFriendlyName(true)+")");
}
}
System.out.print("Choose the device to search for Obex Push service : ");
BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));
String chosenIndex=bReader.readLine();
int index=Integer.parseInt(chosenIndex.trim());
//check for obex service
RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(index-1);
UUID[] uuidSet = new UUID[1];
uuidSet[0]=new UUID("1105",true);
System.out.println("\nSearching for service...");
agent.searchServices(null,uuidSet,remoteDevice,bluetoothServiceDiscovery);
try {
synchronized(lock){
lock.wait();
}
}
catch (InterruptedException e) {
e.printStackTrace();
}
if(connectionURL==null){
System.out.println("Device does not support Object Push.");
}
else{
System.out.println("Device supports Object Push.");
}
}
/**
* Called when a bluetooth device is discovered.
* Used for device search.
*/
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
//add the device to the vector
if(!vecDevices.contains(btDevice)){
vecDevices.addElement(btDevice);
}
}
/**
* Called when a bluetooth service is discovered.
* Used for service search.
*/
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
if(servRecord!=null && servRecord.length>0){
connectionURL=servRecord[0].getConnectionURL(0,false);
}
synchronized(lock){
lock.notify();
}
}
/**
* Called when the service search is over.
*/
public void serviceSearchCompleted(int transID, int respCode) {
synchronized(lock){
lock.notify();
}
}
/**
* Called when the device search is over.
*/
public void inquiryCompleted(int discType) {
synchronized(lock){
lock.notify();
}
}//end method
}//end class
but got the following error:
但出现以下错误:
Native Library intelbth_x64 not available
Native Library bluecove_x64 not available
Exception in thread "main" javax.bluetooth.BluetoothStateException: BlueCove libraries not available
at com.intel.bluetooth.BlueCoveImpl.createDetectorOnWindows(BlueCoveImpl.java:896)
at com.intel.bluetooth.BlueCoveImpl.detectStack(BlueCoveImpl.java:439)
at com.intel.bluetooth.BlueCoveImpl.access0(BlueCoveImpl.java:65)
at com.intel.bluetooth.BlueCoveImpl.run(BlueCoveImpl.java:1020)
at java.security.AccessController.doPrivileged(Native Method)
at com.intel.bluetooth.BlueCoveImpl.detectStackPrivileged(BlueCoveImpl.java:1018)
at com.intel.bluetooth.BlueCoveImpl.getBluetoothStack(BlueCoveImpl.java:1011)
at javax.bluetooth.LocalDevice.getLocalDeviceInstance(LocalDevice.java:75)
at javax.bluetooth.LocalDevice.getLocalDevice(LocalDevice.java:95)
at BluetoothServiceDiscovery.main(BluetoothServiceDiscovery.java:42)
while coding in eclipse. I am using bluecove 2.1.0 and a 64-bit version of Windows 8.
在 Eclipse 中编码时。我使用的是 bluecove 2.1.0 和 64 位版本的 Windows 8。
Can anyone please suggest me a fix?
任何人都可以建议我修复吗?
回答by user1546499
these two links helped me a lot
这两个链接对我帮助很大
this is compatible 64bits
这是兼容的 64 位
http://snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.62/
http://snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.62/
documentation
文件
回答by djilk
There is even a newer version: http://snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.63/
甚至还有更新的版本:http: //snapshot.bluecove.org/distribution/download/2.1.1-SNAPSHOT/2.1.1-SNAPSHOT.63/
Also, it's important to note that this replacesany other bluecove jar. Because the message indicated missing libraries, I initially addedthis, and it caused a version conflict.
此外,重要的是要注意这会替换任何其他 bluecove jar。因为消息指出缺少库,所以我最初添加了这个,它导致了版本冲突。
回答by user2063688
Actually the JAR you have added does not contains x64 dll. Download the JAR from the below link and use it. It worked for me. http://www.java2s.com/Code/Jar/b/Downloadbluecove211jar.htm
实际上,您添加的 JAR 不包含 x64 dll。从以下链接下载 JAR 并使用它。它对我有用。 http://www.java2s.com/Code/Jar/b/Downloadbluecove211jar.htm