0

this is how I set my alarm clock:

//all this inside a onClickListener
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH, 30);
cal.set(Calendar.MONTH, 8);
cal.set(Calendar.YEAR, 2020);

Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM);
intent.putExtra(AlarmClock.EXTRA_HOUR, Integer.parseInt(str1));
intent.putExtra(AlarmClock.EXTRA_MINUTES, Integer.parseInt(str2));
intent.putExtra(AlarmClock.EXTRA_MESSAGE, title.getText().toString());
intent.putExtra(AlarmClock.EXTRA_DAYS, cal.get(Calendar.DAY_OF_MONTH));
intent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
startActivity(intent);

All this set very well the app alarm clock on my device regarding the time, but not for the date.

Example:

  1. Current time: 12:00 Monday

    Time from my code: 13:00 Saturday

    The alarm clock sets to play (the ringtone) in 1 hour

  2. Current time: 12:00 Monday

    Time from my code: 11:00 Tuesday

    The alarm clock sets to play (the ringtone) in 25 hours

I dont know how to use in particular this line of code:

intent.putExtra(AlarmClock.EXTRA_DAYS, cal.get(Calendar.DAY_OF_MONTH));

Thanks in advance

KKKKK
  • 273
  • 2
  • 18
  • 1
    No. You're supposed to pass an ArrayList of the `Calendar` constants for days of the week to set the alarm on. You can't set a specific date. – Nicolas Aug 15 '20 at 18:04
  • Does this answer your question? [How does AlarmClock.EXTRA\_DAYS work - Android Studio](https://stackoverflow.com/questions/43391350/how-does-alarmclock-extra-days-work-android-studio) – Nicolas Aug 15 '20 at 18:06
  • @Nicolas no unfortunately – KKKKK Aug 15 '20 at 18:12

1 Answers1

1

You cannot set the an alarm for a specific date with an AlarmClock provider.

AlarmClock.EXTRA_DAYS is for repeating alarms. You could use something like Calendar.SUNDAY and it would ring every Sunday.

If you want more control over an alarm, you have to program it yourself. Look into the AlarmManager class. It allows you to schedule your application to be run at some point in the future.

einUsername
  • 1,569
  • 2
  • 15
  • 26