private static void RegisterAndroidBatteryChangedBroadcastReceiver() { if (_batteryChangedBroadcastReceiver == null) { _batteryChangedBroadcastReceiver = new BatteryChangedBroadcastReceiver(); } var filter = new IntentFilter(); filter.AddAction(Intent.ActionBatteryChanged); Android.App.Application.Context.RegisterReceiver(_batteryChangedBroadcastReceiver, filter); }
private static void UnregisterAndroidBatteryChangedBroadcastReceiver() { //two events use this broadcast if (_batteryStatusChanged != null || _remainingChargePercentChanged != null) { return; } if (_batteryChangedBroadcastReceiver != null) { Android.App.Application.Context.UnregisterReceiver(_batteryChangedBroadcastReceiver); _batteryChangedBroadcastReceiver = null; } }