WinPhone8 Development Notes (1): how to get the device power information?

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In the power aspect support in WP8 SDK, we can get the power remaining percentage in the application, use the remaining time and other related information.

1, Need to use what?

     Battery.RemainingChargePercent: The percentage of remaining battery power supply for mobile phone.

     Battery.RemainingDischargeTime: Access to mobile phone power supply remaining time display.

     Battery.RemainingChargePercentChanged: The remaining power change event handling.

2, The following code:

using Windows.Phone.Devices.Power; public partial class SystemPage : PhoneApplicationPage { readonly Battery _battery; public SystemPage() { InitializeComponent(); //Gets the current device power objects,Be careful: 不需要创建对象实体 _battery = Battery.GetDefault(); _battery.RemainingChargePercentChanged += _battery_RemainingChargePercentChanged; //Update the user interface UpdateUI(); } //The power percentage change, UpdateUI void _battery_RemainingChargePercentChanged(object sender, object e) { UpdateUI(); } void UpdateUI() { this.tblBatteryChargePercent.Text = string.Format("{0} %", _battery.RemainingChargePercent); //Displays the remaining power use time,Be careful: RenainingDischargeTimeContains a variety of formats of the time display,Self value. this.tblBatteryDisplayTime.Text = string.Format("{0} Minute", _battery.RemainingDischargeTime.TotalMinutes); } }

Note: when starting, power object to obtain the current equipment in the constructor of the MainPage, when the power entrusted to handle the declaration to the change. Define the update method, when there is a power changes, timely interaction with UI.

3, Screenshot below

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Rachel at November 22, 2013 - 5:10 PM