我正在尝试设置一个重复警报,它将每分钟下载一个文件,但仅在 8:00 到 22:00 之间。我觉得我真的很接近,但我看不到我正在犯的错误。当前广播接收器未激活。如果手动设置重复报警为alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+10000, 60000,pendingIntent); 它工作正常。任何指导将不胜感激。
protected void scheduleNextUpdate()
{
Intent intent = new Intent("TEST");
PendingIntent pendingIntent =
PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
int updateInterval = 1;
long nextUpdate =(60000 * updateInterval);
long currentTimeMillis = System.currentTimeMillis();
long nextUpdateTimeMillis = currentTimeMillis + nextUpdate;
Time nextUpdateTime = new Time();
nextUpdateTime.set(nextUpdateTimeMillis);
if (nextUpdateTime.hour < 8 || nextUpdateTime.hour > 22)
{
nextUpdateTime.hour = 8;
nextUpdateTime.minute = 0;
nextUpdateTime.second = 0;
nextUpdateTimeMillis = nextUpdateTime.toMillis(false) + DateUtils.DAY_IN_MILLIS;
}
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+10000, nextUpdateTimeMillis,pendingIntent);
boolean alarmUp = (PendingIntent.getBroadcast(this, 0,
new Intent("TEST"),
PendingIntent.FLAG_NO_CREATE) != null);
if (alarmUp)
{
Log.d("myTag", "Alarm is already active");
}
}