android 取消多个闹钟,android – 如何取消这个重复的闹钟?

博主为用户写提醒,设置重复警报触发状态栏通知,但选择或清除通知后警报不停,不知在哪取消重复闹钟。文中给出设置重复闹钟和显示通知的代码,最后询问当用户选择或清除通知时,如何停止警报。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在为用户写一个提醒。用户将为其事件设置提醒,当时间到来时,将设置重复的警报以触发状态栏通知。但是,在我选择通知或清除通知后,报警似乎不停止。我不知道在哪里取消这个重复的闹钟。以下是一些代码:

在我的主要活动中设置重复的闹钟

alarmTime = Calendar.getInstance();

Intent intent = new Intent(this, AlarmReceive.class);

PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0);

AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

alarmTime.add(Calendar.MINUTE,offset_time);

//Schedule the alarm

alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, alarmTime.getTimeInMillis(), 30 * 1000, sender);

在我的OnReceive方法中,我只是在状态栏中显示通知,并将标志设置为FLAG_AUTO_CANCEL

manager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);

// Set the icon, scrolling text and timestamp

Notification notification = new Notification(R.drawable.medical, text, System.currentTimeMillis());

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, 0);

notification.flags = Notification.FLAG_AUTO_CANCEL;

manager.notify(R.string.service_text, notification);

当用户选择通知或清除通知时,如何停止警报?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值