我想知道是否可以使用 blue cove 将设备永久置于查询模式。
这实际上是代码,它只会让设备在很短的时间内处于查询状态。
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();
}
}
}
}