How to get the battery power level in % in Java in a platform independent way?
Asked Answered
E

2

6

How to get the battery power level in % in Java in a platform independent way?

There is already a question for Windows for this: How to get the remaining battery life in a Windows system?

And for Mac: Get battery level in Java

But how can I do it in a platform-independent way, so it works on Windows, Mac, Linux, and maybe other platforms too?

Equilateral answered 30/8, 2013 at 13:48 Comment(1)
Since all those answers require some kind of native code to access that information, you'd have to provide an implementation for every supported platform anyways. In that case you could try and create your own common interface.Crawly
S
6

There's no "platform-independent" way to read battery levels; that sort of hardware information is extremely OS-specific. The only way to have a "platform-independent" Java interface would be to write a JNI wrapper for each target platform.

(Actually, on Linux it's pretty easy; all this information is exposed as text files under /proc/acpi/battery, so you wouldn't need any JNI there. I don't think OS X has the same friendly presentation, and I'm quite certain Windows doesn't.)

Savannasavannah answered 30/8, 2013 at 13:53 Comment(0)
D
1

I do not think there is any way to do this, once I was writing project to get Windows machine HW details like CPU temperature, and I had to use java native interface with specific libraries. Getting this for different Windows versions was not that straight forward so I do not think you can do this.

Dronski answered 30/8, 2013 at 13:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.