Since Android 5.1 (API Level 22), AlarmManager's setRepeating method forcefully raise intervals under 1 minute (60000 msec) to 1 minute. Although it is completely right decision because waking up phone every 15 seconds or 30 seconds is crazy, but SOMETIMES (for testing, researching, ...) we need such kind of 'bad' alarms. However, we can overcome this shortcoming by setting once-only alarm repetitively(not explicitly calling setRepeating but call set or setExact again and again, like a chain).
For example, previously we have alarms like this:
mAlarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(this, PeriodicWorker.class); alarmIntent.setAction(ACTION_WAKEUP); PendingIntent pendingAlarmIntent = PendingIntent.getService(this, 0, alarmIntent, 0); mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(), ALARM_INTERVAL, pendingAlarmIntent);
However, from the API Level 22 (Android 5.1), we have to do it manually like this:
if (mAlarmManager == null) mAlarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(this, PeriodicWorker.class); alarmIntent.setAction(ACTION_WAKEUP); PendingIntent pendingAlarmIntent = PendingIntent.getService(this, 0, alarmIntent, 0); mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + ALARM_INTERVAL, pendingAlarmIntent);
'Computer' 카테고리의 다른 글
알라딘 인터넷서점 취약점 보고 (0) | 2016.11.01 |
---|---|
Python str <-> datetime <-> timestamp (0) | 2016.09.20 |
2016 SCPC 2차 온라인 예선 3번 - 땅 나누기 (6) | 2016.07.21 |
Strikers 1945 II AI (2) | 2016.03.24 |
Windows 8에서 TOEIC 성적표 PDF로 뽑기 (5) | 2016.03.16 |