From f8039312c5af3c2ee7cf7fd5b7c3aade5c8274eb Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 11 Sep 2024 16:11:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E9=BD=90=E7=9A=84=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E4=B8=8D=E4=BC=A0=E5=BF=83=E8=B7=B3=E5=91=A8=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/xypower/mpapp/MicroPhotoService.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 1c568c5f..cc5cd41a 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -437,7 +437,7 @@ public class MicroPhotoService extends Service { nextPhotoTime *= 1000; if (nextPhotoTime > ts) { mHeartbeatDuration = (int) ((nextPhotoTime - ts) % duration) + 999; - registerHeartbeatTimer(); + registerHeartbeatTimer(false); mHeartbeatDuration = duration; } else { mHeartbeatDuration = duration; @@ -448,13 +448,20 @@ public class MicroPhotoService extends Service { mHeartbeatDuration = duration; } } + private void registerHeartbeatTimer() { + registerHeartbeatTimer(true); + } + + private void registerHeartbeatTimer(boolean normalDuration) { // 创建延迟意图 long triggerTime = System.currentTimeMillis() + mHeartbeatDuration; Intent alarmIntent = new Intent(); alarmIntent.setAction(ACTION_HEARTBEAT); - alarmIntent.putExtra("HeartbeatDuration", mHeartbeatDuration); + if (normalDuration) { + alarmIntent.putExtra("HeartbeatDuration", mHeartbeatDuration); + } alarmIntent.putExtra("HeartbeatTime", triggerTime); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);