Short: Is there some listener to get notified when internet connection becomes available for the app?
Long:
I'm adding some feature to a data field that fetches things from a web api. I want to support as many devices as possible, so I make the web requests from the background app. This already works, when everything is OK, but sometimes there's no internet. Currently I register for the temporal even when I need it, and if there's no internet then it'll return something like responseCode: -104. So currently all I can do is to register for another temporal event 5 minutes later and hope that there will be internet.
So I thought I could be smarter. But the only way I could make it now is to check System.getDeviceSettings().connectionAvailable and only call Background.registerForTemporalEvent() if there's internet NOW (even when I want to trigger the event to be a few minutes in the future). This would not be a big problem, but because I can only trigger the background process every 5 minutes, this doesn't really work.
I couldn't find any listener that I could register for getting events when the internet becomes available. Is there no way to know it besides "polling" the device settings?
I am thinking about some smarter way to do it, but it would need me to build some framework around this... Like:
In the foreground process "register" for temporal event by saving the moment when I want the temporal event to run at the earliest, and set a timer, and when the timer triggers check for the internet, and if available, then trigger the background immediately, if not then reschedule the timer for later and re-check every X minutes.