0

I am developing an application to check whether the lappy is running on power supply or on it battery. Please, tell me how to do it. I have already written the code to detect the battery charge detector.

Pankaj Kumar Thapa
  • 131
  • 1
  • 2
  • 6
  • could you specify your target os? this has nothing to do with java as this depends entirely on the os – gigadot Oct 27 '12 at 04:58
  • 5
    ...and we don't "tell you how to do it", this is a assistance website, not a "throw me some codes so I can copy and paste" one. – Kyle Yeo Oct 27 '12 at 04:59

2 Answers2

1

This is not the kind of things that Java is good for. There are no standard Java APIs for doing this kind of thing. So generally you would need to use System.exec(...) to run some operating system / hardware specific command to give you the information, or use some operating system / hardware specific native library.

Since you haven't told us what your operating system or hardware are, we can't even tell you if this is feasible.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • hi @stephen C, thank you very much for your suggestion. The OS i m working in is for windows 7. It will of great help if I get this answer from you :). – Pankaj Kumar Thapa Oct 27 '12 at 09:07
0

I'm pretty sure there is no java api for this that is pure java. The JVM sits on top of the OS and isn't designed for machine specific (hardware specific) or OS specific applications. Java can call native code through JNI or System calls. See this other SO question.

Community
  • 1
  • 1
Thorn
  • 4,015
  • 4
  • 23
  • 42