0
我正在创建具有闹钟功能的闹钟应用程序。时间显示正常,我也正确设置了多个闹钟。Android中的闹钟设置关闭和打开
我使用不同的ID创建多个警报,并将其保存到数据库中,以便我可以在列表视图中查看警报列表。现在我正在尝试为我的闹钟设置开启和关闭功能。那里有问题。
在itemClick在如果报警后它将切断的帮助下:
Intent intent = new Intent(Main.this,TaskRecieverForAlarm.class);
PendingIntent pi = PendingIntent.getBroadcast(Main.this, Integer.parseInt(cont[0]), intent, 0);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.cancel(pi);
上面的代码取消报警完美的罚款。
要打开我使用的报警:一旦
Intent intent = new Intent(Main.this, TaskRecieverForAlarm.class);
intent.putExtra("AlarmDate", cont[1]);
intent.putExtra("key", Integer.parseInt(cont[0]));
PendingIntent sender = PendingIntent.getBroadcast(Main.this, Integer.parseInt(cont[0]) , intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
if(type.equalsIgnoreCase("daily"))
{
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 1440*60000 ,sender);
}
else if(type.equalsIgnoreCase("weekly"))
{
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 7*1440*60000 ,sender);
}
现在,当我点击OFF到ON,报警触发和调用TASKReceiverFORAlarm(广播接收器),即使报警时间为4或5距离当前时间的小时。我不确定我哪里出错了?
有人可以帮我吗?
谢谢!
我认为你需要使用'FLAG_CANCEL_CURRENT',而不是'FLAG_UPDATE_CURRENT',但这只是一个猜测。请尝试一下,并在这里回顾结果。 – g00dy
改变了它,但仍然一样。 PendingIntent sender = PendingIntent.getBroadcast(Main.this,Integer.parseInt(cont [0]),intent,PendingIntent.FLAG_UPDATE_CURRENT); TO PendingIntent sender = PendingIntent.getBroadcast(Main.this,Integer.parseInt(cont [0]),intent,PendingIntent.FLAG_CANCEL_CURRENT); – Mary
好的,这不起作用,请尝试下面的解决方案。 – g00dy