问题描述
我正在构建一个警报应用程序.我已经成功实现了基本的报警功能.
I'm building an alarm application. I have successfully implemented basic alarm functions.
Calendar calendar = Calendar.getInstance();
calendar.set(calendar.HOUR_OF_DAY, sHour);
calendar.set(calendar.MINUTE, sMin);
calendar.set(calendar.SECOND, 0);
calendar.set(calendar.MILLISECOND, 0);
long sdl = calendar.getTimeInMillis();
Intent intent = new Intent(AlarmList.this, AlarmReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(AlarmList.this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager ALARM1 = (AlarmManager)getSystemService(ALARM_SERVICE);
ALARM1.set(AlarmManager.RTC_WAKEUP, sdl, sender);
在我的应用程序中,用户可以选择天 (sunday,monday...)
每周重复一次闹钟.我正在尝试创建多个警报以每周重复一次,但不知道该怎么做.我可以使用(重复)间隔创建它还是应该创建多个警报管理器?
In my application, user can select days (sunday,monday...)
to repeat the alarm weekly.I'm trying to create multiple alarms to repeat weekly but don't know how to do it.Can I create it using (repeat) interval or should I create multiple alarm managers?
推荐答案
您需要为 pending Intents
使用不同的广播 ID
.就像是这个:
You need to use different Broadcast id's
for the pending intents
. Something likethis:
Intent intent = new Intent(load.this, AlarmReceiver.class);
final int id = (int) System.currentTimeMillis();
PendingIntent appIntent = PendingIntent.getBroadcast(this, id, intent, PendingIntent.FLAG_ONE_SHOT);
使用系统时间应该是每个待处理的唯一标识符意图你开火.
Using the system time should be a unique identifier for every pendingintent you fire.
这篇关于如何在android中使用闹钟管理器设置多个闹钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!