Get battery level in Java

I would like to make a java application that shows the current battery level of my Mac OS X.

I read get system information at OS level and wondered how I can change this to display the current% battery

thanks

+3
source share
3 answers

I think you have two options.

One of them is to use JNI to call your own code to get the battery level.

Another is to call the application pmsetusing System.execin java and parse the output. I think the arguments for extracting the battery level are pmset -g ps, but it is better to check the man page

+2

API Mac OS X:

( ) / API- , /System/Library/Frameworks/IOKit.framework/Headers/ps. , IOPowerSources.h IOPSKeys.h, . , , , .

[]

JNI IOKit.

+1

OS X, /proc linux, , System.exec JNI.

0
source

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


All Articles