Simple Android Question: When we want to check net...
# android
s
Simple Android Question: When we want to check network connectivity in Android, connectivity manager has API of checking capability. Should we… • Get all available networks and then check each network’s capability and if any network has internet capability and if any network has capability then return true • Get active network, check if it has network capability or not What should be the approach and what will be the behaviour difference with both the approaches?
😶 2
c
Can you explain why you're checking for connectivity? My initial thought would be to use the active network connectivity because that is the network the device will attempt to use for communication, which is what you care about most of the time. But typically the best solution regardless seems to be to just try and make your network request and then handle the errors when it doesn't work, since you'll be needing to do that anyway. Pre-emptively checking for network connectivity hasn't ever given any of the projects I've worked on any advantage I can put forward here. Of course this is all my experience, I'd love someone to tell me I'm wrong 😄.