DEV Community

Discussion on: Android 12 gets a... Battery

Collapse
 
jeikabu profile image
jeikabu • Edited

Plenty of devices running Android don't have batteries: "smart" TVs, set-top boxes, etc. Power source: yes, battery: maybe. Perhaps they're trying hard to avoid null.

Anyway, it is interesting to see how to inspect the API.

Collapse
 
tkuenneth profile image
Thomas Künneth

I agree. Regarding trying hard to avoid null: maybe the InputDevice should have the hasBattery() method instead. Then the api flow would be:

if (inputDevice.hasBattery()) {
  val battery = inputDevice.getBattery()
Enter fullscreen mode Exit fullscreen mode

getBattery() might always be non-null, nonetheless. Just feel that query method should not be there :-)