如何取消重复报警?

编程入门 行业动态 更新时间:2024-10-17 00:26:38
本文介绍了如何取消重复报警?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在写东西像一个提醒用户。用户将设置提醒他们的活动,在时机成熟时,重复报警将被设置为触发状态栏通知。但报警器似乎不停止后,我选择了通知或清除的通知。我不知道在哪里可以取消重复报警。下面是一些C $ CS的$的:  设置重复报警器在我的主要活动

I'm writing something like a reminder for users. Users will set reminders for their events, when the time comes, a repeating alarm will be set to trigger a status bar notification. But the alarm seems non-stop after I selected the notification or cleared the notification. I am not sure where to cancel this repeating alarm. Below are some of the codes: Set up the repeating alarm in my main activity

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

In my OnReceive method, I just display the notification in status bar and set the flag as 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);

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

How can I stop the alarm when the user selects the notification or clears it?

推荐答案

呼叫取消()在 AlarmManager 与等效 PendingIntent 来你使用一个 setRepeating():

Call cancel() on AlarmManager with an equivalent PendingIntent to the one you used with setRepeating():

Intent intent = new Intent(this, AlarmReceive.class); PendingIntent sender = PendingIntent.getBroadcast(this, 0, intent, 0); AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmManager.cancel(sender);

更多推荐

如何取消重复报警?

本文发布于:2023-11-27 07:46:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637164.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!