警报管理器在Android中立即触发

编程入门 行业动态 更新时间:2024-10-23 23:19:33
本文介绍了警报管理器在Android中立即触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

奇怪的是,即使当前时间大于一天后运行的警报时间,即使我提出了条件,我的警报管理器也会立即调用待处理的意图。

Strangely, my Alarm Manger is calling the pending intent immediately, even though I have put a condition if the current time is greater than alarm time run one day later.

p>

I have alarm Manger to trigger everyday at 10PM.

Intent startServiceIntent = new Intent(this, numbers.class); this.startService(startServiceIntent); Calendar cal = Calendar.getInstance(); cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(res.getString(R.string.hoursvalue))); //10 cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.AM_PM, Calendar.PM); cal.set(Calendar.MILLISECOND, 0); long alarmtime = cal.getTimeInMillis(); Log.e("ALarm","Time"+alarmtime); if (currenttime > alarmtime) { alarmtime = alarmtime + AlarmManager.INTERVAL_DAY; Log.e("Current Time","Greater"+alarmtime); } if (currentapiVersion >= 19) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent2 = new Intent(this, ServiceForLoadingOnlineNumbers.class); PendingIntent pi = PendingIntent.getService(this, 741258963, intent2, 0); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, alarmtime, AlarmManager.INTERVAL_DAY, pi); } else if (currentapiVersion >= 16 && currentapiVersion < 19) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent3 = new Intent(this, ServiceForLoadingOnlineNumbers.class); PendingIntent pi = PendingIntent.getService(this, 741258963, intent3, 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarmtime, AlarmManager.INTERVAL_DAY, pi); }

日志会以毫秒为单位正确显示第二天,但会立即触发。

The Log shows the next day in milliseconds correctly but triggers immediately. What could be the issue here?

推荐答案

我建议检查警报管理器是否为空,然后在设置警报之前取消警报。以我为例:

I suggest checking if the alarm manager is null then canceling the alarm before setting the alarm this took me some time example

if(alarmManger != null){ alarmManger.cancel(operation); alarmManger.setRepeating(alarmType,alarmtime,‌​AlarmManager.INTERVAL_DAY, operation); }

更多推荐

警报管理器在Android中立即触发

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

发布评论

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

>www.elefans.com

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