Android Question How to test Internet connection without hanging?

Michael Müller Anywhere

Licensed User
Longtime 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


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