Search code examples
androidresourcesdrawablepower-managementresource-id

Android: How can I get Battery Icon Resource ID or full file path/name in Status Bar?


I want to examine whether the battery icon and level in status bar are changed correctly, so I want to get the Battery Icon Resource ID or the full file path/name in Status Bar.

I tried to use the Battery Manager to get the icon's resource ID:

intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, 0)

However, I encountered the same problem as the author did: Android: access "system"-drawables

I get the same icon, whose path is /res/drawable/stat_sys_battery.xml, no matter what the level is. I am eager to know why is this icon not the same with status bar's icon? My goal is to get the status bar's icon.

I have searched for the answer for quite a while, but most posts on this topic pertain to changing the battery icon in status bar, whereas my question is on how to get the status bar's status and icon, i.e. I do not want to modify the icon.

Please help me! Thanks in advance.


Solution

  • I am eager to know why this icon is not the same with status bar's icon.

    It is the same as the status bar's icon, because it is the status bar's icon. The battery level is a LevelListDrawable as implemented in that resource.

    Unless you are building your own custom firmware, you do not have access to the actual LevelListDrawable object, and therefore you cannot examine it.