I had a widget with a countdown timer what worked fine in Android 4.1. But I tried in 5.1 and its not working anymore. Reading blogs and the documentation its a change in that android version
This is my code in my onEnabled in the AppWidgetProvider class
@Override
public void onEnabled(Context context) {
super.onEnabled(context);
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, AlarmManagerBroadcastReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ 100 * 1, 1000 , pi);
}
I read that setRepeating is not more support and I should use setExact or something. It didnt work too.
The best solution is implement a WakefulBroadcastReceiver but I dont know how to launch his onReceive method every second to update the widget.