Querying the Current Connection State
If an application needs to know the connection state infrequently, it can be useful to poll for it directly. The method getConnectivityStatus() returns true if any interface is connected. If a specific interface is required, you can use isWiFiConnected(), isCellularConnected(), or getCurrentConnectivityTypes().