package bluetoothexample; import java.io.IOException; import java.util.Vector; import javax.bluetooth.*; /** * * Class that discovers all bluetooth devices in the neighbourhood, * */ public class BluetoothExample implements DiscoveryListener { { BluetoothExample be=new BluetoothExample(); //display local device address and name LocalDevice localDevice = LocalDevice.getLocalDevice(); //find devices DiscoveryAgent agent = localDevice.getDiscoveryAgent(); ///////////////////////////////////////////////////// //System.out.println("Starting device inquiry...");// ///////////////////////////////////////////////////// agent.startInquiry(DiscoveryAgent.GIAC, be); try { synchronized(lock) { lock.wait(); } } e.printStackTrace(); } ///////////////////////////////////////////////////// //System.out.println("Device Inquiry Completed. ");// ///////////////////////////////////////////////////// //print all devices in vecDevices int deviceCount=vecDevices.size(); if(deviceCount <= 0){ } else { for (int i = 0; i) { try { RemoteDevice remoteDevice = (RemoteDevice) vecDevices.elementAt(i); System.out.println((i + 1) + ". " + remoteDevice.getBluetoothAddress() + " (" + remoteDevice.getFriendlyName(true) + ")"); } } } } /** * Called when a bluetooth device is discovered. * Used for device search. */ public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) { //add the device to the vector if(!vecDevices.contains(btDevice)) { vecDevices.addElement(btDevice); } } /** * Called when a bluetooth service is discovered. * Used for service search. */ public void servicesDiscovered(int transID, ServiceRecord[] servRecord) { if(servRecord!=null && servRecord.length>0) { connectionURL=servRecord[0].getConnectionURL(0,false); } synchronized(lock) { lock.notify(); } } /** * Called when the service search is over. */ public void serviceSearchCompleted(int transID, int respCode) { synchronized(lock) { lock.notify(); } } /** * Called when the device search is over. */ public void inquiryCompleted(int discType) { synchronized(lock) { lock.notify(); } }//end method }//end class
BlueCove version 2.1.0 on bluez
Address: 00805A20EB9C
Name: hormiga-0
Bluetooth Devices:
1. 001E3BA57B16 (Libelula)
2. 0025C7339785 (Mosquito)
3. 0017E5D82BB0 (Tarantula)
4. 001F5DBFF001 (Cucaracha)
BlueCove stack shutdown completed
Invocation:
java -jar "BluetoothExample.jar"
Require
Require bluecove lib, this library is inside of lib folder.