我对 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);