power-management

How can I intercept the push of the physical power button in Windows?

梦想与她 提交于 2019-11-30 21:23:02
Is there any way to intercept the event of the physical power button being pressed in order to react to this event? i.e.: Push button -> My program catches the event -> My program performs action. My goal is to write a C# program/service that will listen for the power button event and then open the "Ask me what to do" shutdown dialog (Like it did back in the days of Windows XP). You could use SystemEvents.SessionEnding Event However I am not sure if this will work if the power button is pressed, this event Occurs when the user is trying to log off or shut down the system. I can explain it to

C#: How to prevent a laptop from going into Stand-By

巧了我就是萌 提交于 2019-11-30 13:14:49
How can I do this in a C# program? I'm pretty sure it should be possible, since various media programs for example do this so the computer doesn't go into stand-by while watching a movie, etc. So, if I for example create a plain and basic WinForm application, what do I need to do to prevent a laptop from going into Stand-By as long as this application is running? I think you'll have to P/Invoke. But don't be scared... it's pretty easy. SetThreadExecutionState is your friend. It's available in the PInvoke project , also available on NuGet . 来源: https://stackoverflow.com/questions/789039/c-how

How do I check when the computer is being put to sleep or wakes up?

六眼飞鱼酱① 提交于 2019-11-30 08:54:31
问题 I want to make my program aware of the computer being put to sleep or waking up from sleep, possibly have an event that is triggered when either of these occur. Is this possible? 回答1: You can subscribe to the SystemEvents.PowerModeChanged event. SystemEvents.PowerModeChanged += OnPowerChange; void OnPowerChange(Object sender, PowerModeChangedEventArgs e) { switch ( e.Mode ) { case PowerModes.Resume: ... case PowerModes.Suspend: ... } } 来源: https://stackoverflow.com/questions/1562474/how-do-i

Launching NFC when screen is Locked in Android

爱⌒轻易说出口 提交于 2019-11-30 08:20:30
I want to launch My Application when we taps on NFC tag even Phone is Locked same as did in Google Wallet Application . I tried in following ways : 1) Tap NFC tag to launch my application after pressing Power button - Error : 05-23 22:00:22.949: D/NfcService(32443): EnableDisableDiscoveryTask: enable = false 05-23 22:00:22.964: D/NfcService(32443): NFC-C polling OFF 05-23 22:00:22.996: D/PhoneStatusBar(273): disable: < EXPAND icons alerts TICKER system_info BACK* HOME* RECENT CLOCK* > 05-23 22:00:23.988: D/NfcService(32443): NFC-EE routing OFF [10:33:22 AM IST] 2)Tap NFC tag after pressing

How can I intercept the push of the physical power button in Windows?

青春壹個敷衍的年華 提交于 2019-11-30 05:27:25
问题 Is there any way to intercept the event of the physical power button being pressed in order to react to this event? i.e.: Push button -> My program catches the event -> My program performs action. My goal is to write a C# program/service that will listen for the power button event and then open the "Ask me what to do" shutdown dialog (Like it did back in the days of Windows XP). 回答1: You could use SystemEvents.SessionEnding Event However I am not sure if this will work if the power button is

iPhone GPS - Battery Draining Extremely Fast

大憨熊 提交于 2019-11-29 21:15:45
问题 We are developing an app that has heavy GPS usage, and we are unable to optimize the battery life. Even when the device is not moved, there is significant battery drainage that, according to the code, should not happen. Here is the code: locationManager = [[CLLocationManager alloc] init]; locationManager.distanceFilter = 100; locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; [locationManager startUpdatingLocation]; Ideally we want to trigger GPS every 20 minutes (if there is

C#: How to prevent a laptop from going into Stand-By

北城以北 提交于 2019-11-29 18:32:05
问题 How can I do this in a C# program? I'm pretty sure it should be possible, since various media programs for example do this so the computer doesn't go into stand-by while watching a movie, etc. So, if I for example create a plain and basic WinForm application, what do I need to do to prevent a laptop from going into Stand-By as long as this application is running? 回答1: I think you'll have to P/Invoke. But don't be scared... it's pretty easy. SetThreadExecutionState is your friend. It's

Monitor battery charge with Win32 API

随声附和 提交于 2019-11-29 10:40:29
I'm trying to write a small app that monitors how much power is left in a notebook battery and I'd like to know which Win32 function I could use to accomplish that. For Vista and up you can use RegisterPowerSettingNotification For earlier functions see the Power Management Functions in this section of the MSDN page "Power Management Functions: Windows Server 2003 and Earlier" You can see example code of the Vista method on codeproject . I recommend the use of the Win32 GetSystemPowerStatus function. A code snippet : int getBatteryLevel() { SYSTEM_POWER_STATUS status; GetSystemPowerStatus(

How is the Android battery health determined?

北城以北 提交于 2019-11-29 07:16:18
I am not talking about how to read the value. Rather, I am interested in how the value of BatteryManager.EXTRA_HEALTH is being set. Does it come from the firmware? Manufacturer specific? What determines these values? int BATTERY_HEALTH_COLD int BATTERY_HEALTH_DEAD int BATTERY_HEALTH_GOOD int BATTERY_HEALTH_OVERHEAT int BATTERY_HEALTH_OVER_VOLTAGE int BATTERY_HEALTH_UNKNOWN int BATTERY_HEALTH_UNSPECIFIED_FAILURE Thanks, Simon To be more specific: The battery health is determined by the driver (in the kernel). Said driver exports information via the sys file system (/sys/class/power_supply, to

How do you get the current battery level in .NET CF 3.5?

℡╲_俬逩灬. 提交于 2019-11-29 05:18:40
How - or what's the best way - to retrieve the device's current battery level in .NET CF 3.5 on Windows Mobile 5 and 6? Noldorin I think you want to use the Microsoft.WindowsMobile.Status namepsace (specifically the SystemState class. using Microsoft.WindowsMobile.Status; ... BatteryLevel batteryLevel = SystemState.PowerBatteryStrength; BatteryState batteryState = SystemState.PowerBatteryState; See this post for the full code sample. You probably want the State Notification Broker class that Noldorin is recommending. I don't think it gives you very fine grain information. You get information