We have added support for power supply in the WP8 SDK. We can get the remaining power usage percentage and remaining time in the application.
1. What do I need?
Battery. remainingchargepercent: gets the percentage of remaining power from the phone.
Battery. remainingdischargetime: Get the remaining display time of the phone power supply.
Battery. remainingchargepercentchanged: event processing when the remaining power changes.
2,CodeAs follows:
using Windows. phone. devices. power; public partial class systempage: phoneapplicationpage {readonly battery _ battery; Public systempage () {initializecomponent (); // obtain the power object of the current device. Note: you do not need to create the object entity _ battery = battery. getdefault (); _ battery. remainingchargepercentchanged + = _ battery_remainingchargepercentchanged; // update the UI void _ battery _ when the power usage percentage changes _ Remainingchargepercentchanged (Object sender, Object E) {updateui ();} void updateui () {This. tblbatterychargepercent. TEXT = string. format ("{0} %", _ battery. remainingchargepercent); // display the remaining battery usage time. Note: renainingdischargetime can be displayed in multiple formats. This. tblbatterydisplaytime. Text = string. Format ("{0} minutes", _ battery. remainingdischargetime. totalminutes) ;}
Note: at startup, obtain the power object of the current device in the mainpage constructor and declare the delegate processing when the power usage changes. Define the update method. When the power usage changes, interact with the UI in a timely manner.
3. as follows: