Beispiel #1
0
        /// <summary>
        /// Gets the state of the charger.
        /// </summary>
        /// <returns><c>true</c>, if charger state was gotten, <c>false</c> otherwise.</returns>
        private static bool GetChargerState()
        {
            if (chargerMonitor != null && chargerConnected.HasValue)
            {
                return(chargerConnected.Value);
            }

            var intent = new IntentFilter(Intent.ActionBatteryChanged).RegisterReceiver();

            if (intent == null)
            {
                return(false);
            }

            int status = intent.GetIntExtra(Android.OS.BatteryManager.ExtraStatus, -1);

            return(status == (int)Android.OS.BatteryPlugged.Ac || status == (int)Android.OS.BatteryPlugged.Usb);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the state of the charger.
        /// </summary>
        /// <returns><c>true</c>, if charger state was gotten, <c>false</c> otherwise.</returns>
        private static bool GetChargerState ()
        {
            if (chargerMonitor != null && chargerConnected.HasValue) {
                return chargerConnected.Value;
            }

            var intent = new IntentFilter (Intent.ActionBatteryChanged).RegisterReceiver ();
            if (intent == null) {
                return false;
            }

            int status = intent.GetIntExtra (Android.OS.BatteryManager.ExtraStatus, -1);
            return (status == (int)Android.OS.BatteryPlugged.Ac || status == (int)Android.OS.BatteryPlugged.Usb);
        }