Winphone8 Development Notes (1): How do I obtain device power information?

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.