我想知道是否可以使用蓝色海湾永久地将设备置于查询模式。
实际上这是代码,它只会让设备在短时间内进行查询。
public class DescobrirDispositivos {
/**
* @param args
* @throws BluetoothStateException
* @throws InterruptedException
*/
public static final Vector/*<RemoteDevice>*/ devicesDiscovered = new Vector();
public static void main(String[] args) throws BluetoothStateException,
InterruptedException {
final Object inquiryCompletedEvent = new Object();
DiscoveryListener listener = new DiscoveryListener() {
@Override
public void servicesDiscovered(int arg0, ServiceRecord[] arg1) {
// TODO Auto-generated method stub
}
@Override
public void serviceSearchCompleted(int arg0, int arg1) {
// TODO Auto-generated method stub
}
@Override
public void inquiryCompleted(int discType) {
synchronized (inquiryCompletedEvent) {
inquiryCompletedEvent.notifyAll();
}
}
@Override
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {
devicesDiscovered.addElement(btDevice);
System.out.println("Device " + btDevice.getBluetoothAddress()
+ " found");
try {
System.out.println("Name " + btDevice.getFriendlyName(false));
} catch (IOException cantGetDeviceName) {
// TODO Auto-generated catch block
}
}
};
synchronized (inquiryCompletedEvent) {
boolean started = LocalDevice.getLocalDevice().getDiscoveryAgent()
.startInquiry(DiscoveryAgent.GIAC, listener);
if (started) {
inquiryCompletedEvent.wait();
}
}
}
}
答案 0 :(得分:0)
不,没有永久性调查的概念。它的用例并不多,因为它会消耗大量的电量,单个查询周期足以发现大多数附近的设备。但是如果你想继续进行查询,那么每次结束时重新启动查询都是微不足道的。