Exemplo n.º 1
0
        /// <summary>
        /// Returns current battery information.
        /// </summary>
        /// <returns>Power information.</returns>
        public override PowerInfo GetPowerInfo()
        {
            PowerInfo pi = new PowerInfo();
            pi.Level = SystemInformation.PowerStatus.BatteryLifePercent * 100;

            if (SystemInformation.PowerStatus.PowerLineStatus == PowerLineStatus.Online)
            {
                pi.Time = -1;
                if (pi.Level == 100.0)
                {
                    pi.Status = Unity.Core.System.PowerStatus.FullyCharged;
                }
                else
                {
                    pi.Status = Unity.Core.System.PowerStatus.Charging;
                }
            }
            else
            {
                pi.Time = (SystemInformation.PowerStatus.BatteryLifeRemaining * 1000);
                pi.Status = Unity.Core.System.PowerStatus.Discharging;
            }
            return pi;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets Power Information (level & status) 
        /// </summary>
        /// <returns>
        /// A <see cref="PowerInfo"/>
        /// </returns>
        public override PowerInfo GetPowerInfo()
        {
            PowerInfo pi = new PowerInfo();
            UIDevice.CurrentDevice.BatteryMonitoringEnabled = true;
            pi.Level = UIDevice.CurrentDevice.BatteryLevel * 100;

            // TODO calculate power remaining time.
            pi.Time = -1;

            if(UIDevice.CurrentDevice.BatteryState == UIDeviceBatteryState.Unplugged) {
                pi.Status = Unity.Core.System.PowerStatus.Discharging;
            } else if (UIDevice.CurrentDevice.BatteryState == UIDeviceBatteryState.Charging) {
                pi.Status = Unity.Core.System.PowerStatus.Charging;
            } else if (UIDevice.CurrentDevice.BatteryState == UIDeviceBatteryState.Full) {
                pi.Status = Unity.Core.System.PowerStatus.FullyCharged;
            } else {
                pi.Status = Unity.Core.System.PowerStatus.Unknown;
            }

            UIDevice.CurrentDevice.BatteryMonitoringEnabled = false;

            return pi;
        }