1

What is the best way to detect if a user has network service when a user has entered the London Underground?

I've tried the following;

ConnectivityManager conMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if(conMgr.getNetworkInfo(0).isAvailable() || conMgr.getNetworkInfo(1).isAvailable())
{
    // Application online
}

I've also tried getting the network level, but this seems to return the last level before the tube has entered the underground.

Any suggestions gratefully appreciated.

Tsuma-Shifu
  • 283
  • 1
  • 4
  • 9

1 Answers1

1

I'm using this code:

public boolean isOnline(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        if (netInfo != null && netInfo.isConnectedOrConnecting()) {
            return true;
        }

        return false;
    }

from thread How to check internet access on Android? InetAddress never times out

Community
  • 1
  • 1
fabian
  • 208
  • 4
  • 8