title: Update Android Widget at Midnight
body: <p>How to update Android widget everyday at midnight?? Below solution is formed by looking at other questions in stack overflow regarding to this topic.</p>
  
  <p>1) schedule(context) is called when widget is created in the activity that extends AppWidgetProvider</p>
  
  <pre><code>    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
          final int N = appWidgetIds.length;
          schedule(context);
      super.onUpdate(context, appWidgetManager, appWidgetIds);
  
  }
  </code></pre>
  
  <p>2) Schedule method should set a timer and alarm so that the widget gets updated at everyday at midnight. however this doesn't work.</p>
  
  <pre><code>protected void schedule(Context context) {
      final Intent i = new Intent(context, CalendarWidget.class);
      service = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
  
      Calendar calendar = Calendar.getInstance();
      calendar.setTimeInMillis(System.currentTimeMillis());
      calendar.set(Calendar.SECOND, 0);
      calendar.set(Calendar.MINUTE, 0);
      calendar.set(Calendar.HOUR, 0);
      calendar.set(Calendar.AM_PM, Calendar.AM);
      calendar.add(Calendar.DAY_OF_MONTH, 1); 
  
      AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
  
  //This doesn't work
         // alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(), service);
  //This doesn't work either.
          alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, service);
      }
  </code></pre>
  
  <p>The solution doesn't work; and it is hard to test it because it can be tested only at midnight everyday; hence, the bounty. I will awarded it to the first person that makes it work.</p>