I asked this question about using the system-drawables in an Android-app some time ago:
Android: access "system"-drawables
I finally found out, that there actually is a way to access those drawables, but especially concerning the battery-icons, there's a catch: it doesn't work as expected. :)
As e.g. trying to acccess the "empty battery"-icon with R.drawable.stat_sys_battery_0
did not work, I found this: intent.getIntExtra(BatteryManager.EXTRA_ICON_SMALL, -1)
which actually does return the integer-ID of "stat_sys_battery_0" and let's me access it, but the documentation states it should return an "icon indicating the current battery state". But actually, I'm always getting the icon for the empty battery no matter what the battery-level is. This happens in the emulator as well as on my phone.
What I tried:
The drawable-ID I get from getIntExtra
is "17302150" (in the emulator and on the phone). Using this ID, I get the "empty battery"-icon. I played around with the IDs, and found some other battery icons by using random IDs, so my thought was to just try and find the IDs of all needed icons and put them in my code statically.
Now, two questions:
1. Is it safe to use static IDs in an app or are the drawable-IDs subject to change throughout SDK-levels or on different devices?
2. As that's just a workaround: Does anybody know why I keep getting the same drawable from getIntExtra
?
Any help is appreciated.