Search code examples
androidsdkbattery

How to change a picture by an event in Android?


I am developing a battery status app and I want to change the battery picture when the battery level of the phone change, for example from 50% to 45% the battery picture should change its status too. How can I do that?

Thank you


Solution

  • You cannot monitor the battery level in Android, you can only monitor the charging state or significant changes of the battery level. Read the documentation.

    Short form: monitoring the state constantly has a bigger impact on battery life than your app itself, it wouldn't make any sense.

    As for changing images, you can use setImageResource or setImageDrawable of an ImageView.