0

I'm trying to set an Alarm with AlarmManager. It works fine if I don't subtract any time from it but when I do it doesn't work. I want to set it 5 minutes before a specified time.

    long minute = AlarmManager.INTERVAL_FIFTEEN_MINUTES / 15;

    alarmTime = alarmTime - (minute*5);

    alarm.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime, AlarmManager.INTERVAL_DAY, pIntent);

This doesn't work. It just doesn't go off.

  • did you look at http://stackoverflow.com/a/18646359/1275777? – Noman Arain Nov 11 '13 at 19:31
  • Is `alarmTime` a `long` too? – m0skit0 Nov 11 '13 at 19:33
  • To Norman, yes I did and tried it that way too, it was useless, it didn't work either. – user1780775 Nov 11 '13 at 19:41
  • Can you debug and let us see what's the values for `alarmTime` and `minute` when it fails? – m0skit0 Nov 11 '13 at 19:43
  • @m0skit0 The only way I know how to debug is with toast and the text was too fast but it showed a long number beginning with 1 for alarmTime and minute was 60000 – user1780775 Nov 11 '13 at 19:53
  • Do Log.D(tag, msg); and print alarmTime.toSring(); paste your logcat. – Noman Arain Nov 11 '13 at 19:55
  • The time set by the alarm when 5 is subtracted must be right because when I show the time using the calendar add way it is the alarm time minus 5, like 2:40 would be 2:35. But it doesn't go off... – user1780775 Nov 11 '13 at 19:55
  • @NomanArain I did that now. The value was 1384804500474. – user1780775 Nov 11 '13 at 20:03
  • Can you try: am.set( AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + TWENTY_SECONDS, pIntent); Instead of setRepeating. Also look here: http://www.techrepublic.com/blog/software-engineer/use-androids-alarmmanager-to-schedule-an-event/ – Noman Arain Nov 11 '13 at 20:20
  • @NomanArain but that doesn't include alarmTime, also oes that go off every 7 days too? – user1780775 Nov 11 '13 at 20:28
  • [Learn to use the debugger](http://stackoverflow.com/questions/8551818/how-to-debug-android-application-line-by-line-using-eclipse), it's easy and life-saving. – m0skit0 Nov 11 '13 at 20:37

0 Answers0