2013-07-26 214 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); –