4

我想制作一个 java 应用程序来显示我的 mac OS X 的当前电池电量。

我已经阅读了获取操作系统级别的系统信息,并且想知道如何修改它以使其显示当前的电池百分比

谢谢

4

3 回答 3

2

I think you have two options.

One is to use JNI to invoke native code to get the battery level.

The other is to invoke the application pmset using System.exec in java and parse the output. I think the arguments to retrieve the battery level is pmset -g ps but you better check the man page

于 2009-10-27T19:02:46.033 回答
1

您需要使用 Mac OS X API:

您可以使用位于 /System/Library/Frameworks/IOKit.framework/Headers/ps 中的 I/O Kit 的电源 API 获取有关电源和 UPS(不间断电源)设备的信息。此文件夹中的头文件 IOPowerSources.h 和 IOPSKeys.h 包含用于提取有关外部和内部电源信息的方法和密钥。例如,应用程序可以获取连接的电源列表,请求其电源更改的通知,并确定电池中剩余的电量。

[编辑]

您将需要使用 JNI 来访问 IOKit 框架。

于 2009-10-27T18:00:03.727 回答
0

Without some OS X equivalent to /proc on linux, I doubt you'll get this done without a System.exec or a JNI call.

于 2009-10-27T18:58:31.130 回答