title: Wake up app from sleep at set time
body: <p>I want to send my app to sleep and then wake it up at set times. I have it going to sleep but not waking up.</p>
  
  <p>This sets the wakelock:</p>
  
  <pre><code>private void setWakeLock(){
      System.out.println("wakelock");
      PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
      wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |
              PowerManager.ACQUIRE_CAUSES_WAKEUP
              | PowerManager.ON_AFTER_RELEASE, "DoNotDimScreen");
      wl.acquire();
  }
  </code></pre>
  
  <p>This sets alarms for wake/sleep times:</p>
  
  <pre><code>private void setWakeSleep(){
      java.util.Calendar c = java.util.Calendar.getInstance();
      c.set(java.util.Calendar.HOUR_OF_DAY, 17);
      c.set(java.util.Calendar.MINUTE, 53);
      c.set(java.util.Calendar.MILLISECOND, 0);
      Intent sleepIntent = new Intent("SLEEP_INTENT");
      PendingIntent sleepPendingIntent = PendingIntent.getBroadcast(this, 0, sleepIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
      alarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), sleepPendingIntent);
  
      c.set(java.util.Calendar.HOUR_OF_DAY, 18);
      c.set(java.util.Calendar.MINUTE, 14);
      c.set(java.util.Calendar.MILLISECOND, 0);
      Intent wakeIntent = new Intent("WAKE_INTENT");
      PendingIntent wakePendingIntent = PendingIntent.getBroadcast(this, 0, wakeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
      AlarmManager alarmManager2 = (AlarmManager) getSystemService(ALARM_SERVICE);
      alarmManager2.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), wakePendingIntent);
  }
  </code></pre>
  
  <p>And this is the broadcast receiver:</p>
  
  <pre><code>private BroadcastReceiver receiver = new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
          Time updateHour = new Time();
          updateHour.set(System.currentTimeMillis());         
          if (intent.getAction().equals("SLEEP_INTENT")) {
              System.out.println("sleep");
              wl.release();
          }
          if (intent.getAction().equals("WAKE_INTENT")) {         
              wl.acquire();
              System.out.println("wake");
              //initialise();
          }
      }
  };
  </code></pre>
  
  <p>Any help greatly appreciated!</p>