Android Question Internet Connection

Discussion in 'Android Questions' started by Derek Jee, Aug 24, 2015.

  1. Derek Jee

    Derek Jee Active Member Licensed 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.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Do you want to send the requests when your app is not in the foreground?

    If yes then the I would go for the simplest solution which is to start the process every hour with StartServiceAt and try to send the request.
     
  3. Derek Jee

    Derek Jee Active Member Licensed User

    I want to send them periodically AND when connectivity comes back after a period of no connectivity..
     
  4. Erel

    Erel Administrator Staff Member Licensed 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
     
    MarcoRome and Derek Jee like this.
  5. Derek Jee

    Derek Jee Active Member Licensed User

    Thank you Erel.. The 'smarter' solution will do another day. Will check for connection with a periodical HTTP request,,
     
  6. sorex

    sorex Expert Licensed 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.
     
    Derek Jee likes this.
  7. MarcoRome

    MarcoRome Expert Licensed User

    You can utilize this for check WiFi / Mobile connection:

    Code:
    '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
     
  8. TLD

    TLD Member Licensed User

    when i use this it show missing library refrence so could you provide me the .jar file
     
  9. DonManfred

    DonManfred Expert Licensed User

  10. MarcoRome

    MarcoRome Expert Licensed User

    Library is HERE
     
  11. MarcoRome

    MarcoRome Expert Licensed User

  12. TLD

    TLD Member Licensed User

    thank you and one more library can you provide MSMaterialDrawerBuilder
     
  13. MarcoRome

    MarcoRome Expert Licensed User

    you have already response HERE.
    For next time pls open Thread in right place... Here you question about MSMaterialDrawerBuilder is out place
     
  14. DonManfred

    DonManfred Expert Licensed User

    Have you tried to use the forumsearch?
     
    MarcoRome likes this.
  15. TLD

    TLD Member Licensed User

    i tried bt i can't see ant download option option that why i ask for the help
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice