Is there a way to get battery level only when the level changes?
I know how to get the battery info using Intent.ACTION_BATTERY_CHANGED and then I compare the battery level of it with the last battery level (that I saved before) in case it equals I don’t do anything else I do my stuff.
I also know that ACTION_BATTERY_CHANGED happens when there is battery info change (not only the level) so cause of that I need to check the level. I don’t know why but sometimes it doesn’t work well.
Is there a better way to do it?
There is no other (documented) way to get the battery level. Just ignore the broadcast when the level did not change. As you already do.
You can get the latest status immediately with the following: