views:

731

answers:

3

Windows Mobile devices have different behaviour for suspending when the device is on battery power, or on external power.

in my application, written using VB.net, I need to be able to determine whether the device has external power connected.

is there a method to get this status from the Compact framework?

+1  A: 

if (SystemState.PowerBatteryState & BatteryState.Charging) ...

Max
Will that work after it's fully charged but still plugged in?
cciotti
+2  A: 

If you're using WIndowsMobile 5.0 and later only, the State and Notification Broker is where to look, specifically at the Status namespace.

For broader support, you can detect the state transition (to or from AC power) calling CeRunAppAtEvent (this can set a named event rather than just running an app) with the NOTIFICATION_EVENT_AC_APPLIED or NOTIFICATION_EVENT_AC_REMOVED event codes. This is what the DeviceManagement class in the Smart Device Framework does.

You can detect current state (instead of transitions) by calling GetSystemPowerStatusEx2.

ctacke
A: 

This may go beyond what you were asking but I wrote something on the Windows Mobile Powermanagement APIS. It uses the same APIs that Chris just referenced but is .Net oriented (sorry, it is in C#, not VB.Net).

http://www.codeproject.com/KB/mobile/WiMoPower1.aspx

Joel