AudioHeadsetBatteryMonitor

Reports battery level (0–100) for the most recently active Bluetooth audio device, using the system broadcast Android fires when it learns a connected headset's battery (via HFP AT+IPHONEACCEV, AVRCP GetCapabilities, or vendor profiles).

The broadcast action and extra strings are hidden BluetoothDevice constants but have been stable for years — every music player on Android relies on them. They're protected broadcasts so only the system can send them.

Limitations:

  • Only fires for paired audio devices, not arbitrary BLE peripherals.

  • AirPods on Android typically don't report battery (Apple's protocol isn't parsed by the AOSP stack).

  • Requires the BLUETOOTH_CONNECT runtime permission on API 31+.

Constructors

Link copied to clipboard
constructor(context: Context)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val batteryPercentFlow: StateFlow<Int?>

0–100, or null until the first audio device reports.

Functions

Link copied to clipboard
fun start()
Link copied to clipboard
fun stop()