こんな感じでUnityで取得
using System.Collections; using System.Collections.Generic; using System.Text; using UnityEngine; #if WINDOWS_UWP using Windows.Devices.Power; #endif public class BatteryInfo : MonoBehaviour { [SerializeField] float battery = -1; [SerializeField] string reportStr = ""; // Start is called before the first frame update void Start() { InvokeRepeating("CheckBatteryInfo", 1, 10); } void CheckBatteryInfo() { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("Battery: "); #if WINDOWS_UWP var aggBattery = Battery.AggregateBattery; var report = aggBattery.GetReport(); float per =System.Convert.ToSingle(report.RemainingCapacityInMilliwattHours) / System.Convert.ToSingle(report.FullChargeCapacityInMilliwattHours); // 0 - 1.0f battery = per; stringBuilder.AppendLine("DeviceId: " + aggBattery.DeviceId.ToString()); stringBuilder.AppendLine("Status: " + report.Status.ToString()); //stringBuilder.AppendLine("FullCharge: " + report.FullChargeCapacityInMilliwattHours.ToString()); //stringBuilder.AppendLine("Remaining: " + report.RemainingCapacityInMilliwattHours.ToString()); stringBuilder.AppendLine("Charge Rate: " + report.ChargeRateInMilliwatts.ToString()); stringBuilder.AppendLine("Design Capacity: " + report.DesignCapacityInMilliwattHours.ToString()); #endif reportStr = stringBuilder.ToString(); } public float GetBattery() { return battery; } public string GetReportString() { return reportStr; } }
参考
https://docs.microsoft.com/ja-jp/windows/uwp/devices-sensors/get-battery-info