Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在开发一个 Windows 手机应用程序,但我无法弄清楚每次电池电量变化时如何触发后台任务。我的意思是,我想在每次电池电量耗尽时启动一项任务-1%。我查看了SystemTrigger类,但对电池状态一无所知。有人有想法吗?
您可以使用类似的方法获取当前的电池电量。
int charge = Windows.Phone.Devices.Power.Battery.GetDefault().RemainingChargePercent;
但是我不确定当电池电量不足时您是否能够运行后台任务。您的 backgroundtask 不会连续运行。电话调度程序定义了后台任务何时运行,并且一旦后台任务中的代码结束,它就无法执行任何操作,直到调度程序再次运行它。