static void StartPowerListeners() { if (!Platform.HasApiLevel(BuildVersionCodes.Lollipop)) { return; } powerReceiver = new PowerBroadcastReceiver(OnPowerChanged); Platform.AppContext.RegisterReceiver(powerReceiver, new IntentFilter(PowerManager.ActionPowerSaveModeChanged)); }
static void StopPowerListeners() { if (!Platform.HasApiLevel(BuildVersionCodes.Lollipop)) { return; } try { Platform.AppContext.UnregisterReceiver(powerReceiver); } catch (Java.Lang.IllegalArgumentException) { Debug.WriteLine("Power receiver already unregistered. Disposing of it."); } powerReceiver.Dispose(); powerReceiver = null; }