-1

In Windows power options you can set a specific threshold (%) when OS notifies when if battery is in low/critical level. My question is there away to get this value on my C# UWP application? I cant find an API that provides this functionality to get the value or event from OS.

I would like to know is possible to get the threshold values from OS instead of hard coding values like 0.1 for low and 0.07 for critical. I mean the threshold percentage values in advanced power settings, that user can define.

Mako
  • 1
  • 1
  • Maybe this helps you https://learn.microsoft.com/en-us/windows/uwp/devices-sensors/get-battery-info – Sybren Aug 09 '17 at 17:14

1 Answers1

0

There is no direct API to do it but you can create one.

Here is a sample code

public Page()
{
    ....
    Battery.AggregateBattery.ReportUpdated += AggregateBattery_ReportUpdated;

}

private void AggregateBattery_ReportUpdated(Battery sender, object args)
{
    var batteryReport = Battery.AggregateBattery.GetReport();

    var percentage = (batteryReport.RemainingCapacityInMilliwattHours.Value / (double)batteryReport.FullChargeCapacityInMilliwattHours.Value);

    if ((percentage == 0.1 || percentage == 0.07) && batteryReport.Status == Windows.System.Power.BatteryStatus.Discharging)
    {
        // Your Code
    }
}
Vijay Nirmal
  • 5,239
  • 4
  • 26
  • 59
  • Yes I have done exactly what you shown above, but I would like to know is possible to get the threshold values from OS instead of hard coding 0.1 and 0.07. I mean the threshold percentage values in advanced power settings, that user can define. – Mako Aug 09 '17 at 17:33
  • @Mako I don't think it's possible. Also, add this info in your question – Vijay Nirmal Aug 09 '17 at 17:43
  • Ok, thanks for the answer and feedback. I re-edited the question – Mako Aug 09 '17 at 17:46