Issue
so I have a code that sets up an alarm at a specified time. I'd like to specify the day of the week aswell. So far all examples I have found are using the Calendar class, however, I use AlarmClock. This is my code:
Intent openNewAlarm = new Intent(AlarmClock.ACTION_SET_ALARM);
openNewAlarm.putExtra(AlarmClock.EXTRA_HOUR, Integer.parseInt(time[0]));
openNewAlarm.putExtra(AlarmClock.EXTRA_MINUTES, Integer.parseInt(time[1]));
openNewAlarm.putExtra(AlarmClock.EXTRA_MESSAGE, String.valueOf(reminder.getText()));
openNewAlarm.putExtra(AlarmClock.EXTRA_DAYS, Calendar.SATURDAY);
startActivity(openNewAlarm);
Notice the EXTRA_DAYS line. According to the description:
/**
* Bundle extra: Weekdays for repeating alarm.
* <p>
* Used by {@link #ACTION_SET_ALARM}.
* </p><p>
* The value is an {@code ArrayList<Integer>}. Each item can be:
* </p>
* <ul>
* <li> {@link java.util.Calendar#SUNDAY},
* <li> {@link java.util.Calendar#MONDAY},
* <li> {@link java.util.Calendar#TUESDAY},
* <li> {@link java.util.Calendar#WEDNESDAY},
* <li> {@link java.util.Calendar#THURSDAY},
* <li> {@link java.util.Calendar#FRIDAY},
* <li> {@link java.util.Calendar#SATURDAY}
* </ul>
*/
public static final String EXTRA_DAYS = "android.intent.extra.alarm.DAYS";
Documentation doesn't help me much or I'm unable to understand it:
https://developer.android.com/reference/android/provider/AlarmClock.html#EXTRA_DAYS
https://developer.android.com/reference/java/util/Calendar.html#SUNDAY
If not mistaken, by selecting Calendar.Sunday, when setting up the alarm, sunday should be ticked in the comboBox meaning that this alarm will repeat every sunday, but it doesn't.
How do I manage to select which days of the week should my alarm repeat?
Any help is welcomed and thanks for your time in advance.
EDIT: I'm using the
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>
on my manifest. The alarm works fine, just need to learn how to set the days of the week.
Solution
The value is an {@code ArrayList<Integer>}.
You need to construct an ArrayList<Integer> from Calendar.SATURDAY and pass it to putExtra()
ArrayList<Integer> alarmDays= new ArrayList<Integer>();
alarmDays.add(Calendar.SATURDAY);
openNewAlarm.putExtra(AlarmClock.EXTRA_DAYS, alarmDays);
Answered By - iVoid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.