0

我想知道是否可以使用 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();
            }
        }
    }

}
4

1 回答 1

0

不,没有永久查询的概念。它没有太多用例,因为它消耗的电量非常大,而且一个查询周期就足以发现大多数附近的设备。但是,如果您想继续进行查询,每次查询结束时重新启动查询是微不足道的。

于 2012-09-07T17:28:41.610 回答