My widget sometimes does not receive the intent ACTION_BATTERY_CHANGED

Good evening, I wrote a tutorial on how to write a widget to display the battery level on Android, but I found that my widget does not always synchronize with what is shown on the "About Phone> Status" screen. I installed a closed source widget to find out if it is always in sync with the “official” value.

You can get the full code here https://github.com/hmrocha/Batteroid and the tutorial here http://androidappdev.org/2011/05/29/androidappdev-batteroid/

For my question, I will post my onReceive method here so you can see if there is a problem:

public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

    if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
        Integer level = intent.getIntExtra("level", -1);
        this.views.setTextViewText(R.id.battery_level, level.toString());
        ComponentName cn = 
            new ComponentName(context, BatteroidAppWidgetProvider.class);
        AppWidgetManager.getInstance(context).updateAppWidget(cn, this.views);
    }
    super.onReceive(context, intent);
}

, ACTION_BATTERY_CHANGED. , , , .

.

+3
1

, ACTION_BATTERY_CHANGED , , Intent.ACTION_POWER_DISCONNECTED, ACTION_BATTERY_CHANGED. , , . , , , , , , .

, GeekYouUp Battery Widget .

GeekYouUp http://programmerbruce.blogspot.com/2011/05/fixing-geekyouups-battery-widget.html.

+2

All Articles