Retreiving the Remaining time of the Windows Phone 8 device battery programatically using C#

In my previous blog post , i explained How to retreive the Battery Level programatically in Windows Phone 8 ?

In this blog post , i will explain how the Windows Phone developers could retreive the estimated or the remaining time of device battery programatically using C#.

How to retreive the Remaining time of the Windows Phone 8 device battery programatically using C# ?

The Battery class includes the property RemainingDischargeTime which is a read only property that gets the time left for the windows phone device battery to be fully discharged.

Get the access to the Battery instance with the Battery.GetDefault() and then use the property RemainingDischargeTime to retreive the time left.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PhoneApp3
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            // SK - To display the Remaining time
            MessageBox.Show(Windows.Phone.Devices.Power.Battery.GetDefault().RemainingDischargeTime.TotalMinutes.ToString());

        }

    }
}

Note that when you use the the RemainingDischargeTime , it will show you a invalid remaining time but should work fine on the windows phone device.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

This blog post will guide you through several effective methods to troubleshoot and resolve the issue of Microsoft Edge not...
Windows 11 offers a range of audio enhancements that can enrich your listening experience. These enhancements include features like virtual...
Windows 11 brings a fresh and visually stunning design to your desktop, and one of the standout features is the...