Show battery level of connected bluetooth device [Kotlin]

912 Views Asked by At

Is it possible to show the battery level of a connected bluetooth device? I'm making an app that monitors devices and it connects thru bluetooth. I know how to show current batterylevel of the monitor (in this case a tablet), but I'm not sure if it's possible to see other battery levels. If anyone has idea's, please comment! Thanks

1

There are 1 best solutions below

2
RatherBeSailing On

In Kotlin

try {
    val headsetBatteryLevel = connectedHeadset.javaClass.getMethod("getBatteryLevel").invoke(connectedHeadset) as Int
    writeToLog("Battery level $headsetBatteryLevel%")
} catch (ex: Exception) {
    writeToLog("Failed to obtain battery level")
}