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


x

Related Posts

Using DebuggerDisplay attribute in C#
DebuggerDisplay attribute class in C# lets the developer control on how an object or property needs to be displayed in the debugger variable wind...
How to Get Type Name without full namespace in C# ?
If you want to find the full name of the type in C# , you can use the typeof keyword to do it as shown in the below code snippet. var str1 = typ...
Constant->static and readonly->instance field in C#
There are 2 options for the developers to declare a constant value in their C# application.1. readonly2. const If you need to initialize a consta...
powered by RelatedPosts