2013-07-26 239 views
2

嗨我希望我的应用程序每天在特定时间运行。为此我使用下面的代码。但它只运行一次。这里有什么错误,我该如何实现这一任务。在特定时间每天重复报警(报警管理器)

AlarmManager alarmMgr0 = (AlarmManager)getSystemService(Context.ALARM_SERVICE); 
Intent intent0 = new Intent(this, ActivityStarter.class); 
PendingIntent pendingIntent0 = PendingIntent.getBroadcast(this, 0, intent0, 0); 
Calendar timeOff9 = Calendar.getInstance(); 
timeOff9.set(Calendar.HOUR_OF_DAY, 16); 
timeOff9.set(Calendar.MINUTE, 13); 
timeOff9.set(Calendar.SECOND, 0); 
alarmMgr0.setRepeating(AlarmManager.RTC_WAKEUP, timeOff9.getTimeInMillis(),24*60*60*1000,pendingIntent0); 

请任何帮助。

回答

4

试试这个

alarmMgr0 .setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 
     SystemClock.elapsedRealtime() + AlarmManager.INTERVAL_DAY, 
     AlarmManager.INTERVAL_DAY, intent); 

参考this

+0

什么你的答案,这之间的区别:)mgr.setInexactRepeating(AlarmManager.RTC_WAKEUP, \t \t \t \t \t calendar.getTimeInMillis(,AlarmManager.INTERVAL_DAY ,pi); –