Android的闹钟 - 编程删除报警 [英] Android Alarm Clock - Remove alarms programmatically

查看:362
本文介绍了Android的闹钟 - 编程删除报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于Android的闹钟 - 编程删除报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆