1

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

mohammed_sajid
  • 233
  • 2
  • 18

1 Answers1

0

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")
}
RatherBeSailing
  • 261
  • 1
  • 11
  • 1
    What is connectedHeadset ? can you please specify some about the same. – Bhavin Solanki Sep 05 '22 at 04:45
  • @BhavinSolanki the above code is inserted when I first check connected Bluetooth speakers. You can find the code in the Work Around under Question 2 here : https://stackoverflow.com/questions/72750231/android-wear-watches-reported-as-connected-bluetooth-headsets – RatherBeSailing Sep 06 '22 at 06:03