我有一个简单的Windows Mobile应用程序,每5分钟记录一次GPS坐标.问题是只要屏幕打开,应用就可以正常工作,只要手机进入待机模式,应用就会停止工作.当我打开设备时,应用程序再次开始工作.
即使在待机模式下,我该怎么做才能让应用程序正常工作?
桑迪普
我使用GPS的经验是需要一段时间来修复(至少在我的设备上),所以我认为你必须始终保持手机处于暂停状态.当我一直在玩我的设备时,我注意到我必须使用内置的音乐播放器在屏幕关闭时进行修复.正如ratchetr所指出的,PowerPolicyNotify(PPN_UNATTENDEDMODE,TRUE)似乎是防止"音乐播放器要求"的正确方法.
编辑:似乎你必须在某些设备上使用SetPowerRequirement/ReleasePowerRequirement.
这是一个C#示例:
public const int PPN_UNATTENDEDMODE = 0x0003;
public const int POWER_NAME = 0x00000001;
public const int POWER_FORCE = 0x00001000;
[DllImport("coredll.dll")]
public static extern bool PowerPolicyNotify(int dwMessage, bool dwData);
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr SetPowerRequirement(string pvDevice, CedevicePowerStateState deviceState, uint deviceFlags, string pvSystemState, ulong stateFlags);
[DllImport("coredll.dll", SetLastError = true)]
public static extern int ReleasePowerRequirement(IntPtr hPowerReq);
public enum CedevicePowerStateState : int
{
PwrDeviceUnspecified = -1,
D0 = 0,
D1,
D2,
D3,
D4,
}
//Keep the GPS and device alive:
PowerPolicyNotify(PPN_UNATTENDEDMODE, true)
IntPtr gpsPowerHandle = SetPowerRequirement("gpd0:", CedevicePowerStateState.D0, POWER_NAME | POWER_FORCE, null, 0);
//Call before exiting your app:
ReleasePowerRequirement(gpsPowerHandle);
PowerPolicyNotify(PPN_UNATTENDEDMODE, false);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8650 次 |
最近记录: |