ostrya / PresencePublisher

An Android MQTT client that regularly publishes messages to notify about the device's presence
MIT License
83 stars 13 forks source link

Inspect all networks to see if wifi is connected #9

Closed Albadon closed 5 years ago

Albadon commented 5 years ago

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.