FileDocCategorySizeDatePackage
BlueLoggerFinder.javaAPI DocExample1532Thu Feb 16 12:50:16 GMT 2006None

BlueLoggerFinder.java

import java.io.IOException;
import javax.bluetooth.*;

public class BlueLoggerFinder implements DiscoveryListener {
  
  private DiscoveryAgent agent;
  private RemoteDevice device;
  
  public static RemoteDevice find() 
   throws BluetoothStateException { 
    BlueLoggerFinder search = new BlueLoggerFinder();
    search.agent = LocalDevice.getLocalDevice().getDiscoveryAgent();
    search.agent.startInquiry(DiscoveryAgent.GIAC, search);
    // wait for inquiry to finish
    synchronized(search){
      try {
        search.wait();
      } 
      catch (InterruptedException ex) {
        // continue
      }
    }
    return search.device;
  }

  public void deviceDiscovered(RemoteDevice device, DeviceClass type) {
    int major = type.getMajorDeviceClass();
    try {
      if (device.getFriendlyName(false).startsWith("Earthmate Blue Logger")) {
        this.device = device;
        // stop looking for other devices
        agent.cancelInquiry(this);
        // wake up the main thread
        synchronized(this){
          this.notify();
        }
      }
    } 
    catch (IOException ex) {
      // Hopefully this isn't the device we're looking for
    }
  }
  
  public void inquiryCompleted(int discoveryType) {}
  
  // This search is only looking for devices and wonâ