check Internet connectivity

Last Updated:

  1. zalani

    zalani Member

    public boolean checkInternetConnection() {
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    // test for connection
    if (cm.getActiveNetworkInfo() != null&& cm.getActiveNetworkInfo().isAvailable()&& cm.getActiveNetworkInfo().isConnected()) {
    return true;
    } else {
    return false;

    // permission used
    <uses-permission android:name="android.permission.INTERNET"/>

  2. LB2064

    LB2064 New Member

    Is there an app that can check internet connectivity and give a notification in the status bar if internet connectivity is lost?
  3. jonbonazza

    jonbonazza Well-Known Member

    I think you are going about this the wrong way. What you need to do is register a BroadcastReciever that listens for a network connectivity change event. Inside your receiver, you should handle the state change depending on whether or network was enabled or disabled. You can even find out what kind of network the event was generated for (i.e. mobile or wifi).

Share This Page