How to get battery power level in% in Java on the platform independently?

How to get battery power level in% in Java on the platform independently?

In Windows, there is already a question for this: How to get the remaining battery life on a Windows system?

And for Mac: Get Battery Level in Java

But how can I make it platform independent, so it works on Windows, Mac, Linux, and possibly other platforms?

+6
source share
2 answers

There is no “platform independent” way of reading battery levels; Such hardware information is extremely OS specific. The only way to have a "platform-independent" Java interface is to write a JNI wrapper for each target platform.

(Actually, on Linux this is pretty simple: all this information is displayed as text files under /proc/acpi/battery , so you don’t need any JNI. I don’t think OS X has the same friendly presentation, and I "Of course, Windows doesn't.)

+6
source

I don’t think there is any way to do this as soon as I write a project in order to get HW details for Windows, such as CPU temperature, and I had to use my own Java interface with specific libraries. Getting this for different versions of Windows was not so straightforward, so I don't think you can do it.

+1
source

Source: https://habr.com/ru/post/952838/


All Articles