locked
How to access Battery information from Metro Apps?

    Question

  • Is there a way to access Battery information from a Metro App? I found a similar forum request posted during Feb'12, I am curious something changed by now.

    Thanks

    PB

    Monday, April 23, 2012 10:09 PM

Answers

  • Hi,

    There is no way to programatically access battery info in Metro style app.

    GetSystemPowerStatus API is used to retrieve the power status of the system. The status indicates whether the system is running on AC or DC power, whether the battery is currently charging, and how much battery life remains.

    It seemingly can meet your needs. However, this API applies to "desktop app only".

    No equivalent for the Power APIs in Metro style app. Please check Alternatives to Windows APIs in Metro style apps

    So you can either develop a desktop app or manually check setting pane to monitor battery status.

    Battery info is maintained by system. Otherwise, I don't know the actual needs for accessing it in Metro style app.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by __PB Tuesday, April 24, 2012 5:03 PM
    Tuesday, April 24, 2012 7:12 AM
    Moderator

All replies

  • Hi,

    There is no way to programatically access battery info in Metro style app.

    GetSystemPowerStatus API is used to retrieve the power status of the system. The status indicates whether the system is running on AC or DC power, whether the battery is currently charging, and how much battery life remains.

    It seemingly can meet your needs. However, this API applies to "desktop app only".

    No equivalent for the Power APIs in Metro style app. Please check Alternatives to Windows APIs in Metro style apps

    So you can either develop a desktop app or manually check setting pane to monitor battery status.

    Battery info is maintained by system. Otherwise, I don't know the actual needs for accessing it in Metro style app.


    Best wishes,


    Robin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by __PB Tuesday, April 24, 2012 5:03 PM
    Tuesday, April 24, 2012 7:12 AM
    Moderator
  • > Battery info is maintained by system. Otherwise, I don't know the actual
    > needs for accessing it in Metro style app.

    For example in our game we limit things to 25 fps to save battery.  I know our game is running on a device plugged into a wall outlet I can disable the frame rate limiter and let it run at a full 60 fps for a much smoother presentation.

    I don't need to know anything more than "is the device plugged into the wall or not" and maybe even "we're in a low battery mode".

      - Tom

    Wednesday, June 13, 2012 11:31 PM
  • It also would be extremely helpful to display a Live Tile of the users current battery life. I have been trying to develop an app of that sort but haven't come up with any solutions. A Metro Battery API would be great!

    - Samuel

    Thursday, June 27, 2013 11:29 PM
  • It also would be extremely helpful to display a Live Tile of the users current battery life. I have been trying to develop an app of that sort but haven't come up with any solutions. A Metro Battery API would be great!

    - Samuel

    It would be awesome to to see more information about the device. If i want to kno the battery level i have to go into the desktop hit the little icon in the notification bar.

    You can not see the percentage when you swipe to the left. Not even in windows 8.1... Still have to use the desktop for infromation.

    Sunday, August 04, 2013 11:03 AM
  • If you want to check if is plugged into the wall you can use

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.background.maintenancetrigger.aspx

    If you get backgroundtaskcancellationreason != abort then you are plugged.

    I was thinking a battery app live tile, could ask the user what run time a full change eg: 4 hours, and then have lock screen a periodic background task updating the live tile badge while not plugged in.

    Wednesday, September 04, 2013 6:16 PM
  • MaintenanceTrigger has a minimum Freshness time of 15 minutes.  Sounds to me you'll only get random updates during each 15-minute interval and not real-time AC/Battery status.  Am I right here?

    Thursday, October 24, 2013 2:20 PM
  • Agreed the precision is not great but its the only way i can see currently to poll the AC/Battery state. But remember in most scenarios the laptops/tablet the AC state wont change often or frequently during an app session. 
    Friday, November 01, 2013 3:23 PM