Android的闹钟 - 编程删除报警闹钟、Android

2023-09-05 08:17:05 作者:半度微凉ら

我写在其中用户可以配置警报/报警的应用程序。在这一点上,我的一切工作没有想到的人。我使用发射了报警

I am writing an application in which user can configure alerts/alarms. At this point, I have everything working expect the one. I am firing off an alarm using

Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
alarmIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
alarmIntent.putExtra(AlarmClock.EXTRA_MESSAGE, "Some message!");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MINUTE, 1);
alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, calendar.get(Calendar.HOUR_OF_DAY));
alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, calendar.get(Calendar.MINUTE));
alarmIntent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
context.startActivity(alarmIntent);

我想删除该报警,一旦用户使用的释放按钮驳回。我能看到的报警是在闹钟我设定使用上述code到我的申请仍然存在。

I want to remove this alarm once user has dismissed using the Dismiss button. I can see the alarms being still there in the alarm clock which I set using above code through my application.

有没有办法让光标或东西的报警是在闹钟有类似的?这将帮助我在它们之间迭代并删除那些我想要的。

Is there some way to get a cursor or something similar on the alarms being there in the alarm clock? This will help me iterate over them and remove the ones I want.

任何帮助将是AP preciated,先谢谢了。

Any help would be appreciated, Thanks in advance.

推荐答案

调用方法取消(...) AlarmManager ,使用相同的 PendingIntent 您用来设置报警。例如:

call method cancel(...) from AlarmManager, using the same PendingIntent you used to set the alarm. Example:

mAlarmPendingIntent = PendingIntent.getActivity(this, requestCode, intent, flags);

this.getAlarmManager().cancel(mAlarmPendingIntent);

活动服务您从中取消报警

this refers to the Activity or the Service from which you are cancelling the alarm