2010/06/24

Detecting network availability on Android

This tip is not really a ‘hidden feature’, but it’s useful and can come in handy if you don’t want to register BroadcastReceiver and add listeners for network events, but just want to check if you have network access at a certain point.

2 comments:

  1. If getSystemService failed to return valid ConnectivityManager and returned null, then return true?

    ReplyDelete
  2. it should never return null, so this is just a workaround, in case for some reason we didn't get the manager, i'd rather try the network than silently fail...

    ReplyDelete