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() {