Interface BluetoothDevice
- All Known Implementing Classes:
AbstractBluetoothDevice, LinuxBluetoothDevice, MacBluetoothDevice
Represents a Bluetooth device (paired or connected) known to the system, analogous to
UsbDevice for USB
peripherals.
Bluetooth devices are enumerated per adapter. Each device reports its name, MAC address, major device class, connection/pairing state, and battery level when available.
Example usage:
for (BluetoothDevice device : hal.getBluetoothDevices()) {
System.out.printf("%s [%s] %s%s (battery: %s)%n", device.getName(), device.getAddress(),
device.getMajorDeviceClass(), device.isConnected() ? " *connected*" : "",
device.getBatteryLevel() >= 0 ? device.getBatteryLevel() + "%" : "N/A");
}
-
Method Summary
Modifier and TypeMethodDescriptionThe name of the adapter (e.g.,hci0) through which this device is known.The MAC address of the Bluetooth device in colon-separated format (e.g.,AA:BB:CC:DD:EE:FF).intThe battery level of the device as a percentage (0–100).The major Bluetooth device class (e.g., "Audio", "Phone", "Computer", "Peripheral", "Networking").getName()The user-visible name of the Bluetooth device.booleanWhether the device is currently connected to this system.booleanisPaired()Whether the device is paired (bonded) with this system.
-
Method Details
-
getName
String getName()The user-visible name of the Bluetooth device.- Returns:
- The device name, or an empty string if unknown.
-
getAddress
String getAddress()The MAC address of the Bluetooth device in colon-separated format (e.g.,AA:BB:CC:DD:EE:FF).- Returns:
- The device MAC address.
-
getMajorDeviceClass
String getMajorDeviceClass()The major Bluetooth device class (e.g., "Audio", "Phone", "Computer", "Peripheral", "Networking").Derived from the Class of Device (CoD) field when available.
- Returns:
- The major device class string, or an empty string if unknown.
-
isConnected
boolean isConnected()Whether the device is currently connected to this system.- Returns:
trueif connected,falseotherwise.
-
isPaired
boolean isPaired()Whether the device is paired (bonded) with this system.- Returns:
trueif paired,falseotherwise.
-
getBatteryLevel
int getBatteryLevel()The battery level of the device as a percentage (0–100).- Returns:
- The battery percentage, or
-1if not available.
-
getAdapterName
String getAdapterName()The name of the adapter (e.g.,hci0) through which this device is known.- Returns:
- The adapter name.
-