本文介绍了覆盖现有报警的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建我的应用程序,它在呼唤一个BroadcastReceiver设置的通知本code以往一天的alaram:

I create an alaram in my app which is calling a BroadcastReceiver to setup notifications ever day with this code:

Intent intent = new Intent(Benachrichtigung.CUSTOM_INTENT);
PendingIntent pendingIntent  = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 8);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);

alram = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alram.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), (24 * 60 * 60 * 1000), pendingIntent);

现在我想用户可以设置时间norification所以我叫 calendar.set 新价值。我怎样才能用新的覆盖现有的报警?

Now I want that the user can set the time for the norification so I have to call calendar.set with the new value. How can I overwrite the existing alarm with a new one?

推荐答案

要取消或使用更新警报 AlarmManager 意图必须使用filterEquals匹配。所以基本上,你当你为重新创建的PendingIntent 相同的原件和 AlarmManager 将看到它们一样。这包括 REQUEST_ code INTENT_ACTION INTENT_DATA (我可能失去了一些东西存在,但这些都是很重要的。

To cancel or update an alarm using AlarmManager the Intent must match using the filterEquals. So basically, you re-create the PendingIntent the same as you did for the original and AlarmManager will see that they are the same. This includes the REQUEST_CODE, INTENT_ACTION, and INTENT_DATA (I may be missing something there but those are important.

注意:

其他在比较不使用两个意图秒。

EXTRAS are not used in comparing the two Intents.

因此​​,如果两个意图是相等,则第一个将被覆盖。当我有更多的时间,我可以尝试找到一个资源更好地说明这一点。

So if the two Intents are equal then the first will be overwritten. When I have more time I can try and find a resource to better explain that.

根据意向文档filterEquals

确定两个意图是意图分辨率(过滤)的目的是一样的。也就是说,如果它们的作用,数据类型,类,和类别是相同的。这不比较列入意图任何额外的数据。

这篇关于覆盖现有报警的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:08