应用程序在待机模式下运行

应用程序在待机模式下运行

本文介绍了保持 Windows Mobile 应用程序在待机模式下运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 Windows Mobile 应用程序,可以记录 GPS 坐标每 5 分钟.问题是只要屏幕上的应用程序就可以正常工作开启,一旦手机进入待机模式,应用程序就会停止工作.当我打开设备时,应用再次开始工作.

I have a simple Windows Mobile application which records GPS coordinatesevery 5 minutes. The problem is the app works fine as long as the screenis on, as soon as the phone goes in standby mode the app stops working.When I switch on the device the app again starts working again.

我该怎么做才能让应用在待机模式下也能正常运行?

What do I do to keep the app working even in standby mode?

桑迪普

推荐答案

我使用 GPS 的经验是修复需要一段时间(至少在我的设备上),所以我认为你必须保持手机不挂起无时无刻不在状态.当我在玩我的设备时,我注意到我必须使用内置的音乐播放器在屏幕关闭时进行修复.正如瑞秋指出的那样 PowerPolicyNotify(PPN_UNATTENDEDMODE,TRUE) 似乎是防止音乐播放器要求"的正确方法.

My experience with GPS is that it takes a while to get a fix (at least on my device), so I think you have to keep the phone from suspended state all the time. When I’ve been playing around with my device I’ve noticed that I have to use the built in music player to get a fix while the screen is off. As ratchetr pointed out PowerPolicyNotify(PPN_UNATTENDEDMODE,TRUE) seems to be the right way to prevent the "music player requirement".

似乎您还必须在某些设备上使用 SetPowerRequirement/ReleasePowerRequirement.

It also seems like you have to use SetPowerRequirement / ReleasePowerRequirement on some devices.

这是一个 C# 示例:

Here is a C# sample:

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

这篇关于保持 Windows Mobile 应用程序在待机模式下运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:54