![](/img/trans.png)
[英]My Java bluetooth server on raspberry pi running debian wheezy needs bluecove native library - where can I find it?
[英]Bluetooth, BlueCove and Raspberry PI
我在RaspberryPI上使用Java使用BlueJ进行设置,并使用Blueman进行了蓝牙设置,并且正在使用BlueCove API。
我从以下示例中获取了RemoteDeviceDiscovery示例:
http://bluecove.org/bluecove/apidocs/overview-summary.html#DeviceDiscovery
当我从BlueJ中运行示例时,我得到:
“等待设备查询完成...设备查询完成!找到0个设备”,当我从终端窗口运行时,使用:
pi @ raspberrypi〜/ java / bluetooth_jar $ / usr / lib / jvm / jdk-8-oracle-arm-vfp-hflt / jre / bin / java -jar bluetooth_jar.jar
我得到:
“ bluez上的BlueCove版本2.1.1-SNAPSHOT BluetoothStateException异常:javax.bluetooth.BluetoothStateException:蓝牙设备未准备好。[1]不允许操作BlueCove堆栈关闭已完成”
为什么在使用BlueJ时未引发异常,我不明白,但是在命令行中,由于设备未准备好,它似乎无法检测附近的设备。 但是,我不明白此错误消息,因为我可以使用Blueman Manager将文件发送到附近的Android平板电脑和Win7笔记本电脑。
import java.io.IOException;
导入java.util.ArrayList; 导入javax.bluetooth。*;
/ ** *最小设备发现示例。 * /公共类RemoteDeviceDiscovery {
protected ArrayList<RemoteDevice> devicesDiscovered = new ArrayList();
protected final Object inquiryCompletedEvent = new Object();
public RemoteDeviceDiscovery()
{
DiscoveryListener listener = new MyDiscoveryListener();
synchronized(inquiryCompletedEvent) {
try
{
LocalDevice local = LocalDevice.getLocalDevice();
local.setDiscoverable(DiscoveryAgent.GIAC);
DiscoveryAgent discoveryAgent = local.getDiscoveryAgent();
// note: GIAC: The inquiry access code for General/Unlimited Inquiry Access Code (GIAC).
boolean startedInquiry = discoveryAgent.startInquiry(DiscoveryAgent.GIAC, listener);
if (startedInquiry)
{
System.out.println("wait for device inquiry to complete...");
inquiryCompletedEvent.wait();
System.out.println(devicesDiscovered.size() + " device(s) found");
}
}
catch ( BluetoothStateException e)
{
System.out.println("BluetoothStateException exception: " + e);
}
catch (InterruptedException e)
{
System.out.println("InterruptedException exception: " + e);
}
}
}
public static void main(String[] args)
{
RemoteDeviceDiscovery rmd = new RemoteDeviceDiscovery();
}
class MyDiscoveryListener implements DiscoveryListener
{
public MyDiscoveryListener()
{
}
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
System.out.println("Device " + btDevice.getBluetoothAddress() + " found");
devicesDiscovered.add(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) {
}
} // class MyDiscoveryListener
} //类RemoteDeviceDiscovery
发现如果我以超级用户权限运行jar,则可以按预期工作:
pi @ raspberrypi〜sudo / java / bluetooth_jar $ / usr / lib / jvm / jdk-8-oracle-arm-vfp-hflt / jre / bin / java -jar bluetooth_jar.jar
输出:
bluez上的BlueCove版本2.1.1-SNAPSHOT等待设备查询完成...设备C4850852975B发现名称GMSEED-PC设备查询已完成! 找到1个设备BlueCove堆栈关闭已完成
如果我以超级用户身份从命令行而不是通过桌面菜单项Menu | Programming | BlueJ启动BlueJ; 即:
pi @ raspberrypi〜$须藤bluej
然后示例应用程序将提供相同的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.