Can anybody see any obvious flaw in that code?
You are assuming that ACTION_BATTERY_CHANGED
has been broadcast, reflecting the new charging status, before whatever broadcast you are listening to ("plugged in/plugged out events") has been broadcast. I am not aware that this is a requirement. If the device sends its "plugged in/plugged out events" before ACTION_BATTERY_CHANGED
, your code will be seeing the last ACTION_BATTERY_CHANGED
, before the "plugged in/plugged out event".