windows mobile 开发:让GPS一直在待机模式下也能运行

最近,遇到一个需求,就是每 30 秒更新一次 GPS 位置,在测试过程中,发现在系统待机后,更新 GPS 位置就不能正常运行了,搜索后,发现如下的解决方案,实际应用了之后,有效,赞!!!

http://stackoverflow.com/questions/873816/keep-windows-mobile-app-running-in-standby-mode

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);
posted @ 2013-12-05 22:39  toddzhuang  阅读(307)  评论(0编辑  收藏  举报