Android Question How to test Internet connection without hanging?

Discussion in 'Android Questions' started by Michael Müller Anywhere, Jan 30, 2015.

  1. Michael Müller Anywhere

    Michael Müller Anywhere Member Licensed User

    my app tries to send a string every 2 minutes to a php-script.
    I am using an activity with buttons and labels and a Service with
    a sub routine that includes:

    Before sending this I have to check if I have internet-connection
    because the activity hangs about 30 seconds when I am sending a string while I am not online.
    (It can be that the user is in a area with very low connection)

    I have already tried the 2 following ways:
    1) ServerSocket.GetMyIP
    this shows me that I am online. But I am not realy online.
    I can test it with a normal browser too:
    It shows me that the websites are not reachable

    a) It works only for 1 call.
    b) The activity hangs too, I can not press a button for round about 30 seconds

    My question:
    Is there a way to test if I have a Internet-connection without hanging
    when I have no connection?

    Or to reduce the hanging time?

    Thank you
  2. tigrot

    tigrot Well-Known Member Licensed User

    Use a ping instead. Look for the code on the forum, it's simple and low weight and gives no impact on your site.
  3. Cableguy

    Cableguy Expert Licensed User

    There is a lib WiFi related that has a "test internet" method. It tests all type of connections and return true or false...
    I just can't remember the name...
  4. lemonisdead

    lemonisdead Well-Known Member Licensed User

    ABWifi ?
    Cableguy and Beja like this.
  5. Cableguy

    Cableguy Expert Licensed User

    Yes, that's the one! Thanks
    lemonisdead likes this.
  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