Possible Duplicate:
How to check internet access on Android? InetAddress never timeouts
I need to detect whether the Android device is connected to the Internet.
The NetworkInfo
class provides a non-static method isAvailable()
that sounds perfect.
Problem is that:
NetworkInfo ni = new NetworkInfo();
if (!ni.isAvailable()) {
// do something
}
throws this error:
The constructor NetworkInfo is not visible.
Safe bet is there is another class that returns a NetworkInfo
object. But I don't know which.
- How to get the above snippet of code to work?
- How could I have found myself the information I needed in the online documentation?
- Can you suggest a better way for this type of detection?