The Mixed Reality Forums here are no longer being used or maintained.
There are a few other places we would like to direct you to for support, both from Microsoft and from the community.
The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.
For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.
If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.
And always feel free to hit us up on Twitter @MxdRealityDev.
Is there a way to get the Battery level from the hololens through Unity?
I need to find a way to get the amount of battery left inside Unity, anyone got this working?
I've looked around for a solution but I cant seem to access System.Management or the Battery Class in Windows.Devices.Power. Any ideas on how to get this information?
Best Answer
-
OptionsHoloSheep mod
When you say inside Unity, do you mean inside an app created in Unity?
Are you wrapping your UWP code with the appropriate compile directives like so?
#if WINDOWS_UWP using Windows.Devices.Power; #endif ... #if WINDOWS_UWP var aggBattery = Battery.AggregateBattery; var report = aggBattery.GetReport(); Debug.Log("Battery Report: DeviceId - " +aggBattery.DeviceId.ToString()); Debug.Log("Battery Report: Status - " + report.Status.ToString()); Debug.Log("Battery Report: FullCharge - " + report.FullChargeCapacityInMilliwattHours.ToString()); Debug.Log("Battery Report: Remaining - " + report.RemainingCapacityInMilliwattHours.ToString()); Debug.Log("Battery Report: Charge Rate - " + report.ChargeRateInMilliwatts.ToString()); Debug.Log("Battery Report: Design Capacity - " + report.DesignCapacityInMilliwattHours.ToString()); #endif
Based on a quick test deployed to a HoloLens I get the following results:
Battery Report: DeviceId - AggregateBattery
Battery Report: Status - Discharging
Battery Report: FullCharge - 16710
Battery Report: Remaining - 15664
Battery Report: Charge Rate - -3409
Battery Report: Design Capacity - 16500(plus a bunch of UnityEngineDebugbinding messages scattered in-between that I didn't bother investigating)
which jives with the 94% that was showing on the device start screen at the time.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings2
Answers
@toban
When you say inside Unity, do you mean inside an app created in Unity?
Are you wrapping your UWP code with the appropriate compile directives like so?
Based on a quick test deployed to a HoloLens I get the following results:
(plus a bunch of UnityEngineDebugbinding messages scattered in-between that I didn't bother investigating)
which jives with the 94% that was showing on the device start screen at the time.
Windows Holographic User Group Redmond
WinHUGR.org - - - - - - - - - - - - - - - - - - @WinHUGR
WinHUGR YouTube Channel -- live streamed meetings
works like a charm