2

I have made an app that allows one to listen to the radio and have implemented an alarm so that I can have the radio play when the alarm goes off. I am using the alarmManager and RTC_wakeup, and it seems to work fine if the phone is plugged in or if the phone is not asleep (which kind of defeats the purpose). When the phone is unplugged and asleep, however, the alarm does not go off until I wake up the phone.

Does anyone know a solution to this?

Tot Zam
  • 8,406
  • 10
  • 51
  • 76
kyle
  • 49
  • 5
  • How is you app made up? What are you using to react to the alrm notification (activity, service, broadcast receiver etc). When you say it works when plugged in, I'm guessing you have 'Stay Awake' enabled in the Applications -> Development settings - not something an end user will normally have. – Squonk Mar 10 '11 at 17:24
  • AlarmManager alarmService = (AlarmManager) getOwnerActivity().getSystemService(Context.ALARM_SERVICE); alarmService.set(AlarmManager.RTC_WAKEUP, today, pendInt); funny thing is that it works when i physically sleep it(hit the power button to sleep it) but if it sleeps it self(after being idle) then it seems to wait until i wake it to call the intent – kyle Mar 10 '11 at 17:58

1 Answers1

1

This is how we did it and it works in both case that you describe:

PendingIntent pi = null;

private void startMonitor() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent i = new Intent(this, OnTickReceiver.class);
    pi = PendingIntent.getBroadcast(this, 0, i, 0);

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis() + 120 * 1000, 120 * 1000, pi);
}

private void stopMonitor() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pi);
}
vsm
  • 3,373
  • 2
  • 25
  • 36