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