Class AbstractBluetoothDevice
java.lang.Object
oshi.hardware.common.AbstractBluetoothDevice
- All Implemented Interfaces:
BluetoothDevice
- Direct Known Subclasses:
LinuxBluetoothDevice, MacBluetoothDevice
Abstract base class for BluetoothDevice implementations.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractBluetoothDevice(String name, String address, String majorDeviceClass, boolean connected, boolean paired, int batteryLevel, String adapterName) Creates an AbstractBluetoothDevice with the given parameters. -
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.static StringparseMajorDeviceClass(int cod) Parses the major device class from the Bluetooth Class of Device (CoD) integer.toString()
-
Constructor Details
-
AbstractBluetoothDevice
protected AbstractBluetoothDevice(String name, String address, String majorDeviceClass, boolean connected, boolean paired, int batteryLevel, String adapterName) Creates an AbstractBluetoothDevice with the given parameters.- Parameters:
name- the device nameaddress- the MAC addressmajorDeviceClass- the major device classconnected- whether the device is connectedpaired- whether the device is pairedbatteryLevel- the battery level (0–100), or -1 if unavailableadapterName- the adapter name
-
-
Method Details
-
getName
Description copied from interface:BluetoothDeviceThe user-visible name of the Bluetooth device.- Specified by:
getNamein interfaceBluetoothDevice- Returns:
- The device name, or an empty string if unknown.
-
getAddress
Description copied from interface:BluetoothDeviceThe MAC address of the Bluetooth device in colon-separated format (e.g.,AA:BB:CC:DD:EE:FF).- Specified by:
getAddressin interfaceBluetoothDevice- Returns:
- The device MAC address.
-
getMajorDeviceClass
Description copied from interface:BluetoothDeviceThe major Bluetooth device class (e.g., "Audio", "Phone", "Computer", "Peripheral", "Networking").Derived from the Class of Device (CoD) field when available.
- Specified by:
getMajorDeviceClassin interfaceBluetoothDevice- Returns:
- The major device class string, or an empty string if unknown.
-
isConnected
public boolean isConnected()Description copied from interface:BluetoothDeviceWhether the device is currently connected to this system.- Specified by:
isConnectedin interfaceBluetoothDevice- Returns:
trueif connected,falseotherwise.
-
isPaired
public boolean isPaired()Description copied from interface:BluetoothDeviceWhether the device is paired (bonded) with this system.- Specified by:
isPairedin interfaceBluetoothDevice- Returns:
trueif paired,falseotherwise.
-
getBatteryLevel
public int getBatteryLevel()Description copied from interface:BluetoothDeviceThe battery level of the device as a percentage (0–100).- Specified by:
getBatteryLevelin interfaceBluetoothDevice- Returns:
- The battery percentage, or
-1if not available.
-
getAdapterName
Description copied from interface:BluetoothDeviceThe name of the adapter (e.g.,hci0) through which this device is known.- Specified by:
getAdapterNamein interfaceBluetoothDevice- Returns:
- The adapter name.
-
toString
-
parseMajorDeviceClass
Parses the major device class from the Bluetooth Class of Device (CoD) integer.The major device class is bits 12–8 of the CoD value.
- Parameters:
cod- the Class of Device integer- Returns:
- a human-readable major device class string
-