From cd35c7f05d58a9034e14ebaea6fcf79ed0576c3e Mon Sep 17 00:00:00 2001 From: Matthew Date: Mon, 29 Apr 2024 22:13:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=BF=83=E8=B7=B3=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=92=8C=E6=8B=8D=E7=85=A7=E6=97=B6=E9=97=B4=E5=AF=B9?= =?UTF-8?q?=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xypower/mpapp/MicroPhotoService.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java index 8685eb9b..7a885606 100644 --- a/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java +++ b/app/src/main/java/com/xypower/mpapp/MicroPhotoService.java @@ -383,11 +383,26 @@ public class MicroPhotoService extends Service { // Will be called fron native private void registerHeartbeatTimer(int duration, long nextPhotoTime) { int orgHeartbeatDuration = mHeartbeatDuration; - mHeartbeatDuration = duration; + if (orgHeartbeatDuration == 0) { - registerHeartbeatTimer(); + if (nextPhotoTime == 0) { + mHeartbeatDuration = duration; + registerHeartbeatTimer(); + } else { + long ts = System.currentTimeMillis(); + nextPhotoTime *= 1000; + if (nextPhotoTime > ts) { + mHeartbeatDuration = (int) ((nextPhotoTime - ts) % duration) + 999; + registerHeartbeatTimer(); + mHeartbeatDuration = duration; + } else { + mHeartbeatDuration = duration; + registerHeartbeatTimer(); + } + } + } else { + mHeartbeatDuration = duration; } - } private void registerHeartbeatTimer() {