classstableSource
@API(status = STABLE)
public class NetworkUtil

Constructors

public NetworkUtil()

Methods

public static void ensureOnline(String action) throws NoConnectionException
Ensures that the user has a working internet connection

Example usage:

try {
    NetworkUtil.ensureOnline("Login");
    // proceed with network operation
} catch (NoConnectionException e) {
    // show/print a human readable message
    System.out.println("You do not have a network connection");
}
The result is remembered for a few seconds
Parameters
actionStringA short description of the action that requires connectivity, e.g. "Login"
Throws
NoConnectionExceptionIf there is no connection