getting battery level at android widget
android, android-widget, battery, receiver
Solution
hackbod gave the solution at the comments:
" use getApplicationContext().registerReciever() "
Problem
I wrote a widget for Android and I'm trying to get the battery level. I've tried using ``` Intent batteryIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); ``` but I get the error: "IntentReceiver components are not allowed to register to receive intents" Why? the ACTION_BATTERY_CHANGED is a sticky intent and I don't register a receiver (null in the first parameter). Any workaround? Thanks.