Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 419
stommestack Avatar asked Aug 30 '13 13:08

stommestack


2 Answers

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.)

like image 91
chrylis -cautiouslyoptimistic- Avatar answered Nov 16 '22 02:11

chrylis -cautiouslyoptimistic-


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.

like image 38
Mateusz Avatar answered Nov 16 '22 03:11

Mateusz