Android里用AlarmManger实现设置闹钟 如何设置之前的时间

2024-11-27 13:05:49
推荐回答(2个)
回答1:

稍微判断一下,我最近刚做了一个定时任务的功能。代码如下
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, planOnOff.hour);
calendar.set(Calendar.MINUTE, planOnOff.minute);
if (System.currentTimeMillis()>calendar.getTimeInMillis()) {
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR)+1);
}
operation = PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 3600*24*1000, operation);
如果觉得赞,给分吧少年!

回答2:

换个软件不就好了,那么多闹钟供你选择呢