See this fooobar.com/questions/1271182 / ... for an API that you can use to receive callbacks at different times regarding sunrise / sunset. This answer explains how to use the API.
This question is slightly different from the other, so I am not duplicating it. The fact that this is related to this issue is that you do not need to pre-calculate the sunrise / set for long periods of time and register a bunch of alarms. In addition to the inelegant solution, the precommute will not work on mobile devices, because the sunrise / installation depends on the location of the device, and you cannot know where the device is for a long time in the future.
With the proposed Awareness API , in particular TimeFence.aroundTimeInstant () , you will automatically receive a callback at a certain offset from sunrise / install, and you can unregister from the API at any time to stop receiving them.
source share