我設置了一個重複報警,我只想在設備醒來時關閉。當它睡着時,我希望它停止(並在設備醒來時再回來)。但是,無論如何,它現在都會關閉。以下是我如何註冊我的鬧鐘:設備睡着時防止報警發生
Intent updateIntent = new Intent(UPDATE_INTENT);
AlarmManager alarmService = (AlarmManager) context.getSystemService(
Context.ALARM_SERVICE);
PendingIntent updatePendingIntent = PendingIntent.getBroadcast(context, 0,
updateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmService.setInexactRepeating(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis(), UPDATE_INTERVAL, updatePendingIntent);
警報管理器文檔說RTC不會喚醒設備。該文檔指定正是我想要的行爲:
Alarm time in System.currentTimeMillis() (wall clock time in UTC). This alarm does not wake the device up; if it goes off while the device is asleep, it will not be delivered until the next time the device wakes up.
當我按下設備上的鎖定按鍵,我清楚地看到了將要在logcat中的PowerManager的睡眠消息:
I/PowerManagerService(488): Going to sleep by user request...
然後我無論如何,警報都會熄滅。這裏發生了什麼?具有諷刺意味的是,我在SO上發現的每一個其他問題都會在設備處於睡眠狀態時警報不起作用。我希望我有他們的問題!
什麼是'UPDATE_INTERVAL'的價值? – codeMagic
出於測試目的,我在10秒鐘(10000)。但是在製作過程中會有幾個小時。 – Adam
你有沒有試過用2或3分鐘測試它?值得嘗試排除。 – codeMagic