每天在特定时间点火的警报

时间:2012-03-13 20:20:12

标签: java android calendar broadcastreceiver alarmmanager


我有一个警报让我们在15点O'Clock说火。
我想让它每天15:00开火。
所以我写了这段代码:

     sender = PendingIntent.getBroadcast(Main.this, ID, intent, 0);
     AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
     Calendar alarm = Calendar.getInstance();
     alarm.setTimeInMillis(System.currentTimeMillis());
     alarm.set(Calendar.HOUR_OF_DAY, 15);
     alarm.set(Calendar.MINUTE, 0);
     long alarmCal=alarm.getTimeInMillis();
     if (alarmCal<=new Date().getTime()) {
        alarm.add(Calendar.DAY_OF_MONTH, 1);
     }
     am.setRepeating(AlarmManager.RTC_WAKEUP, alarm.getTimeInMillis(), AlarmManager.INTERVAL_DAY, sender);

它会在15:00每天真的开火吗?
谢谢!

0 个答案:

没有答案