如何在应用程序运行时保持屏幕显示 [英] How Do I keep the Screen on while my application is running
问题描述
我有一个应用程序,我正在移植到HTC Snap。我希望在我的应用程序运行时保持屏幕打开。我当然可以改变手机设置,永远不要关闭屏幕。但不幸的是,在这款特定手机上,按下按钮无法关闭屏幕上的
。至少我认为没有:我已经检查了手机的手册。因此,我不能要求用户更改手机设置以始终保持屏幕开启,因为他们将无法关闭屏幕
,无法关闭设备。
I have an app that I am porting to HTC Snap. On I would like to keep the screen on while my application is running. I can of course change the phone settings to never turn the screen off. But unfortunately on this particular phone it is not possible to turn the screen off by pressing a button. At least I don't think there is: I have checked the phone's manual. As a result I cannot ask users to change their phone's settings to always keep the screen on because then they would have no way of turning off the screen short of turning off the device.
所以这就是我想做的事情:我想更改手机的设置,以便在我的应用程序启动时保持屏幕亮起并将设置恢复原状在应用程序退出之前的状态。我在
各种论坛上看过类似的问题,但我找不到可能有疑问的答案。
So this is what I woulds like to do: I would like to change the phone's settings to keep the screen on when my application starts and put the settings back to its original state just before the application exits. I have looked at similar questions on the various forums but I could not find an answer to may question.
By顺便说一句,我正在为这个应用程序使用C#和.NET Compact框架。我非常感谢你的帮助。
By the way, I am using C# and the .NET Compact framework for this app. I would very much appreciate some help.
Reza
推荐答案
使用 SystemIdleTimerReset + SHIdleTimerReset 以获得结果。
Use SystemIdleTimerReset + SHIdleTimerReset with Timer (each 9 sec) to get the result.
替代方案是使用 SetSystemPowerState 与 POWER_FORCE flag
和Timer但它可以产生不良结果(某些设备会自行唤醒)。
An alternative is to use SetSystemPowerState with POWER_FORCE flag and Timer but it can produce bad results (some devices will wake up on their own).
这篇关于如何在应用程序运行时保持屏幕显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!