2012-06-05 1 views
3

위해이 지금까지알람 관리기 간격 안드로이드

AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); 
setRepeatingAlarm(); 

public void setRepeatingAlarm() { 

    Calendar cal = Calendar.getInstance(); 
    cal.add(Calendar.SECOND, 10); 

    Intent intent = new Intent(this, TimeAlarm.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 
    am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), (15 * 1000), pendingIntent); 
    } 

} 

이 내가 달성하기 위해 노력하고 모두가 내가 가지고있는 코드입니다. 선택을 취소하면 다음에 분 30 초 전까지 다시 돌아 오지 않습니다. 따라서 앱을 열면 분당 25 초가 지나면 5 초 후 상태 표시 줄 알림이 활성화됩니다. 하지만 40 초가 지나면 50 초를 더 기다려야합니다. 이 기능을 얻기 위해 캘린더 기능을 사용하는 방법을 잘 모르겠습니다.

답변

4

그때 귀하의 요구 사항을 이해한다면 당신은 말한다,

Calendar cal = Calendar.getInstance(); 
if (cal.get(Calendar.SECOND) >= 30) 
    cal.add(Calendar.MINUTE, 1); 
cal.set(Calendar.SECOND, 30); 

// Do the Intent and PendingIntent stuff 

am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60 * 1000, pendingIntent); 
+0

감사합니다. 그것은 작동합니다! – anivaler

0

당신이 AlarmManager에 대한 문서를 선택하면 ... 다음과 같은 일을 시도 할 수있는 RTC_WAKEUP 사용 시간 기준으로 System.currentTimeMillis()에 :

RTC_WAKEUP System.currentTimeMillis()의 알람 시간 (월 시계 시간 (UTC)). 장치가 꺼질 때 장치를 시작합니다.

am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 15 * 1000, pendingIntent); 

그런 다음 알람이 반복 될 15 초마다 실행됩니다 : 예를 바로 시작하는

그래서 간단하게, 당신의 triggerAtTime 매개 변수를 수정합니다.