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

In this post, you’ll learn about the Win32 Error “0x000019E5 – ERROR_COULD_NOT_RESIZE_LOG” that you get when debugging system erors in...
In this post, you’ll learn about the error “CO_E_DBERROR 0x8004E02B” that is returned when working with COM based APIs or...
In this post, you’ll learn about the Win32 Error “0x000019D0 – ERROR_LOG_BLOCK_VERSION” that you get when debugging system erors in...