每天在特定时间设置重复闹钟

编程入门 行业动态 更新时间:2024-10-24 20:14:30
本文介绍了每天在特定时间设置重复闹钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试使用闹钟管理器在每天的特定时间运行闹钟.我正在使用此代码

I try to use alarm manager to run alarm at specific time every day. I am using this code

Intent intent = new Intent(AlarmSettings.this, AlarmService.class); intent.putExtra("i", i); PendingIntent mAlarmSender = PendingIntent.getService(AlarmSettings.this, Id, intent, 0); AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),Calendar.getInstance().getTimeInMillis()+(24*60*60*1000), mAlarmSender);}

问题出在如果 cal.getTimeInMillis() 值在过去,警报会立即运行,我不知道为什么,当 cal.getTimeInMillis() 值在未来时,它会在当时正确运行.

the problem was in if cal.getTimeInMillis() value is in the past the alarm run immediately, i do not know why, and when cal.getTimeInMillis() value is in the future it runs correctly at its time.

我需要让它每天在特定时间运行.

I need to make it run at specific time every day.

推荐答案

这看起来像是你对

setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)

尝试设置适当的 triggerAtTime(将来) - 就像

Try to set proper triggerAtTime (in the future) - like

Calendar.getInstance().getTimeInMillis()+(24*60*60*1000)

第三个参数(间隔)显然应该是你的间隔,比如

The third param (interval) should obviously be your interval, like

24*60*60*1000

更多推荐

每天在特定时间设置重复闹钟

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

发布评论

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

>www.elefans.com

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