如何使用 Intent 设置警报 选择警报的完整日期(包括日、月)
How to set an Alarm Using an Intent Selecting the full date of the alarm (including day, month)
所以我想在我的应用程序中添加一项功能来启动闹钟并设置一个,我尝试使用通常的代码:
Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm");
i.putExtra(AlarmClock.EXTRA_HOUR, 10);
i.putExtra(AlarmClock.EXTRA_MINUTES, 30);
startActivity(i);
它工作正常,唯一的问题是 AlarmClock.EXTRA_HOUR 参数可以是 0 到 24,这意味着我最多会在接下来的 24 小时内设置闹钟,但假设我在周一想设周五闹钟,请问有什么办法吗?
我查看了关于 Android 开发人员的 AlarmClock 文档,只发现了以下可选参数:
EXTRA_HOUR (optional): The hour of the alarm being set.
EXTRA_MINUTES (optional): The minutes of the alarm being set.
EXTRA_DAYS (optional): Weekdays for repeating alarm.
EXTRA_MESSAGE (optional): A custom message for the alarm.
EXTRA_RINGTONE (optional): A ringtone to play with this alarm.
EXTRA_VIBRATE (optional): Whether or not to activate the device
vibrator for this alarm.
EXTRA_SKIP_UI (optional): Whether or not to display an activity for
setting this alarm.
如有任何帮助,我们将不胜感激
您可以使用 EXTRA_DAYS
并仅在您想要的那一天(或几天)启用闹钟。这会创建一个重复警报,因此如果您不希望它重复,则需要在它被触发后将其取消。
所以我想在我的应用程序中添加一项功能来启动闹钟并设置一个,我尝试使用通常的代码:
Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm");
i.putExtra(AlarmClock.EXTRA_HOUR, 10);
i.putExtra(AlarmClock.EXTRA_MINUTES, 30);
startActivity(i);
它工作正常,唯一的问题是 AlarmClock.EXTRA_HOUR 参数可以是 0 到 24,这意味着我最多会在接下来的 24 小时内设置闹钟,但假设我在周一想设周五闹钟,请问有什么办法吗?
我查看了关于 Android 开发人员的 AlarmClock 文档,只发现了以下可选参数:
EXTRA_HOUR (optional): The hour of the alarm being set.
EXTRA_MINUTES (optional): The minutes of the alarm being set.
EXTRA_DAYS (optional): Weekdays for repeating alarm.
EXTRA_MESSAGE (optional): A custom message for the alarm.
EXTRA_RINGTONE (optional): A ringtone to play with this alarm.
EXTRA_VIBRATE (optional): Whether or not to activate the device vibrator for this alarm.
EXTRA_SKIP_UI (optional): Whether or not to display an activity for setting this alarm.
如有任何帮助,我们将不胜感激
您可以使用 EXTRA_DAYS
并仅在您想要的那一天(或几天)启用闹钟。这会创建一个重复警报,因此如果您不希望它重复,则需要在它被触发后将其取消。