I want to send HTTP requests periodically to upload data to my site. I also want to be able to run this process when connectivity becomes available after a period of no connectivity. Is there some way of running some code based on a change of connectivity without having to have a timer checking for a connection? Or can you suggest an alternative if there is one..
The best way to check for connectivity is to try to send a request to the actual server. Therefore I recommend you to try to send a request every few hours.
the phone library also has a connectivity change event that you can use.
if you use a service with a timer you can check on IP address aswell, when it is 0.0.0.0 or 127.0.0.1 it's offline too.
on the other hand, there's not really a need to use it when combined to a 1 minute timer or so as the request will just spit out an error that you can catch.
You can utilize this for check WiFi / Mobile connection:
B4X:
'Chekc Internet connection
'Library for check Connect WiFi
Dim connect_wifi As VBConnect
'Library for check Connect Mobile
Dim ph As Phone
'In this case both ( WiFi / Mobile ) isnt connect
If ph.GetDataState = "DISCONNECTED" And connect_wifi.weconnected = "NO" Then
Msgbox("MSG", "INTERNET CONNECTION LOST")
Activity.Finish
Else
.....
End If
You can utilize this for check WiFi / Mobile connection:
B4X:
'Chekc Internet connection
'Library for check Connect WiFi
Dim connect_wifi As VBConnect
'Library for check Connect Mobile
Dim ph As Phone
'In this case both ( WiFi / Mobile ) isnt connect
If ph.GetDataState = "DISCONNECTED" And connect_wifi.weconnected = "NO" Then
Msgbox("MSG", "INTERNET CONNECTION LOST")
Activity.Finish
Else
.....
End If