本文介绍了在每天的特定时间设置重复警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用警报管理器每天在特定时间运行警报。 我正在使用此代码
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更多推荐
在每天的特定时间设置重复警报
发布评论