나는 매 분마다 경보를 발사하려고합니다. 그러나 어떤 이유로 그것은 일하고 싶지 않습니다. 매분마다 업데이트해야하는 위젯 시계입니다. 배터리 때문에 나는 화면을 켜고 끌 수있는 수신기를 만들었다. 그래서 내 알람은 화면이 켜져있을 때만 발동됩니다. 분은 내 시스템 시계와 동기화되어야합니다.Alarmmanager - 매분마다 화재 경보
public static void startClockTickAlarm() {
AlarmManager alarmManager = (AlarmManager)_context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 1);
calendar.add(Calendar.HOUR, 1);
alarmManager.setRepeating(AlarmManager.RTC, utcMillisNextMin(), 60000, createClockTickIntent(_context));
}
public static final long utcMillisNextMin() {
Time t = new Time();
t.setToNow();
t.second = 0;
t.minute++;
System.out.println("Next Alarm: " + t.hour + ":" + t.minute + ":" + t.second);
return t.normalize(true);
}
내 System.out에서 정확히 무엇을해야하는지 알려줍니다. 예를 들어 나의 위젯을 11시 30 분 15 초에 활성화하면 11시 31 분에 11시 31 분에 11시 31 분에 내 경보가 발생합니다. 내 시스템 클럭에 따르면 알람이 5-15 초 늦었습니다. 알람이 너무 늦게 울리는 시간은 항상 같지 않습니다 (5 초에서 15 초 사이).
미리 감사드립니다.
기기에 어떤 API 수준이 있습니까? –
또한 충돌이 발생하면 logcat 출력을 게시하십시오. –
내 장치는 android 4.4.4이고 21 개를 타겟팅하고 있으며 min api는 14 개입니다. – zFr3eak