Package javax.bluetooth

Examples of javax.bluetooth.DiscoveryAgent


        WiimoteDeviceDiscovery deviceDiscovery = new WiimoteDeviceDiscovery(lock);
        LocalDevice localDevice = LocalDevice.getLocalDevice();
        Log.write("Your Computers Bluetooth MAC: " + localDevice.getBluetoothAddress());

        Log.write("Starting device inquiry...");
        DiscoveryAgent discoveryAgent = localDevice.getDiscoveryAgent();
        discoveryAgent.startInquiry(DiscoveryAgent.GIAC, deviceDiscovery);


        try {
            synchronized (lock) {
                lock.wait();
View Full Code Here


    public BluetoothClient() throws BluetoothStateException {
        LocalDevice localDev = LocalDevice.getLocalDevice();
        System.out.println("Local Bluetooth Name is " + localDev.getFriendlyName());
        localDev.setDiscoverable(DiscoveryAgent.GIAC);
        DiscoveryAgent discovery = localDev.getDiscoveryAgent();
        discovery.startInquiry(DiscoveryAgent.GIAC, this);
    }
View Full Code Here

        LocalDevice localDev = LocalDevice.getLocalDevice();
        //System.out.println("Local Bluetooth Name is "+localDev.getFriendlyName());
        //System.out.println("IAC is "+localDev.getDiscoverable());
        //System.out.println("set Discoverable "+localDev.setDiscoverable(DiscoveryAgent.GIAC));
        //System.out.println("IAC is "+localDev.getDiscoverable());
        DiscoveryAgent discovery = localDev.getDiscoveryAgent();
        System.out.println("Inquiry:" + discovery.startInquiry(DiscoveryAgent.GIAC, this));
    }
View Full Code Here

                String psmString          = url.substring(23, endIndex);
                Short psmShort            = Short.decode(psmString);
                short psm                 = psmShort.shortValue();
                BluetoothStack bluetooth  = BluetoothStack.getBluetoothStack();
                LocalDevice localDev      = LocalDevice.getLocalDevice();
                DiscoveryAgent discovery  = localDev.getDiscoveryAgent();
                RemoteDevice remoteDevice = discovery.getRemoteDevice(remoteAddrLong);
                if (remoteDevice != null) {
                    JSR82Channel channel = new JSR82Channel();
                    bluetooth.connectL2CAPChannel(channel, remoteDevice, psm);
                    return channel;
                }
View Full Code Here

  {
    BluetoothServiceDiscovery bluetoothServiceDiscovery=new BluetoothServiceDiscovery();
    //display local device address and name
    LocalDevice localDevice = LocalDevice.getLocalDevice();
    //find devices
    DiscoveryAgent agent = localDevice.getDiscoveryAgent();

    agent.startInquiry(DiscoveryAgent.GIAC, bluetoothServiceDiscovery);
    try
    {
      synchronized(lock)
      { lock.wait(); }
    }
    catch (InterruptedException e)
    {
      e.printStackTrace();
    }
    Log.append("Device Inquiry Completed. \n");

    int deviceCount=vecDevices.size();
    if(deviceCount <= 0)
    {
      Log.append("No Devices Found .\n");
      return null;
    }
    else
    {
      Log.append("Bluetooth Devices: \n");
      for (int i = 0; i <deviceCount; i++)
      {
        RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(i);
        String t = i + ": \"" + remoteDevice.getFriendlyName(true) + "\"";
        Log.append(t + "\n");
      }
    }
    UUID[] uuidSet = new UUID[1];
    if (ScanForUUID != null)
      uuidSet[0]=new UUID(ScanForUUID, true);
    else
      uuidSet[0]=new UUID("ACDC", true);

    for (int i = 0; i < vecDevices.capacity(); i++)
    {
      RemoteDevice remoteDevice=(RemoteDevice)vecDevices.elementAt(i);
      String t = remoteDevice.getFriendlyName(true);
      agent.searchServices(null,uuidSet,remoteDevice,bluetoothServiceDiscovery);
      try
      {
        synchronized(lock)
        { lock.wait(); }
      }
View Full Code Here

  @Override
  public void run() {
    try {
      LocalDevice localDevice = LocalDevice.getLocalDevice();
      logger.debug("Initializing local bluetooth device ({}, {})", localDevice.getBluetoothAddress(), localDevice.getFriendlyName());
      DiscoveryAgent agent = localDevice.getDiscoveryAgent();
      final Object inquiryCompletedEvent = new Object();

      // this is the call back for the bluetooth driver
      DiscoveryListener listener = new DiscoveryListener() {
       
        public void deviceDiscovered(RemoteDevice btDevice,
            DeviceClass cod) {
          if (!newDevices.contains(btDevice)) {
            newDevices.add(btDevice);
            if (!oldDevices.contains(btDevice)) {             
              BluetoothDevice device = toBluetoothDevice(btDevice);
              logger.debug("Device discovered: {}", device.toString());
              for(BluetoothEventHandler handler : eventHandler) {
                handler.handleDeviceInRange(device);
              }
            }
          }
        }

        public void inquiryCompleted(int discType) {
          // check if any device has disappeared
          for (RemoteDevice btDevice : oldDevices) {
            if (newDevices.contains(btDevice))
              continue;
            BluetoothDevice device = toBluetoothDevice(btDevice);
            logger.debug("Device out of range: {}", device.toString());
            for(BluetoothEventHandler handler : eventHandler) {
              handler.handleDeviceOutOfRange(device);
            }
          }

          oldDevices = new HashSet<RemoteDevice>(newDevices);
         
          // we now pass the list of all devices in range to the event handlers
          Iterable<BluetoothDevice> devices = Iterables.transform(newDevices, new Function<RemoteDevice, BluetoothDevice>() {
            public BluetoothDevice apply(RemoteDevice from) {
              return toBluetoothDevice(from);
            }
          });
          for(BluetoothEventHandler handler : eventHandler) {
            handler.handleAllDevicesInRange(devices);
          }
         
          newDevices.clear();
          synchronized (inquiryCompletedEvent) {
            // tell the main thread that we are done
            inquiryCompletedEvent.notifyAll();
          }
        }

        public void serviceSearchCompleted(int transID, int respCode) {
        }

        public void servicesDiscovered(int transID,
            ServiceRecord[] servRecord) {
        }
      };

      // this is the main loop, which will run as long as the thread is not marked as interrupted
      while (!interrupted) {
        long starttime = new Date().getTime();
       
        // check if we at all need to run the bluetooth discovery
        boolean runDiscovery = false;
        for(BluetoothEventHandler handler : eventHandler) {
          if(handler.isActive()) {
            runDiscovery = true;
            break;
          }
        }
       
        if(runDiscovery) {
          synchronized (inquiryCompletedEvent) {
            try {
              logger.debug("Launching bluetooth device discovery...");
              boolean started = agent.startInquiry(
                  DiscoveryAgent.GIAC, listener);
              if (started) {
                inquiryCompletedEvent.wait();
              }
            } catch (BluetoothStateException e) {
View Full Code Here

TOP

Related Classes of javax.bluetooth.DiscoveryAgent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.