Android Question Internet Connection

Derek Jee

Active Member
Licensed User
Longtime User
Hi there

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..

Kind regards..

Derek.
 

Derek Jee

Active Member
Licensed User
Longtime User
I want to send them periodically AND when connectivity comes back after a period of no connectivity..
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
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.

If you want a "smarter" solution then you can add a static intent filter that will listen to this action: android.net.conn.CONNECTIVITY_CHANGE
See this tutorial: Intent Filters - Intercepting SMS messages in the background
 
Upvote 0

Derek Jee

Active Member
Licensed User
Longtime User
Thank you Erel.. The 'smarter' solution will do another day. Will check for connection with a periodical HTTP request,,
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
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.
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
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
 
Upvote 0

TLD

Member
Licensed User
when i use this it show missing library refrence so could you provide me the .jar file
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
thank you and one more library can you provide MSMaterialDrawerBuilder

you have already response HERE.
For next time pls open Thread in right place... Here you question about MSMaterialDrawerBuilder is out place
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…