When connected to a VPN, ConnectivityManager.getActiveNetwork() returns the VPN's network which doesn't have the TRANSPORT_WIFI NetworkCapabilites flag set.
This causes the app to think there is no wifi connection (only "offline" pings are sent).
This solution uses WifiInfo.getNetworkId() which returns -1 if there is no active wifi network.
The alternative solution would be to iterate over all available networks to see if there is an active wifi network among them.
When connected to a VPN, ConnectivityManager.getActiveNetwork() returns the VPN's network which doesn't have the TRANSPORT_WIFI NetworkCapabilites flag set. This causes the app to think there is no wifi connection (only "offline" pings are sent).
This solution uses WifiInfo.getNetworkId() which returns -1 if there is no active wifi network. The alternative solution would be to iterate over all available networks to see if there is an active wifi network among them.