1. Introducing Channels - a new way to chat with other Android users!
    Dismiss Notice

check Internet connectivity


Last Updated:

  1. zalani

    zalani Member This Topic's Starter

    Joined:
    Feb 2, 2012
    Messages:
    8
    Likes Received:
    0
    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"/>
     

    Advertisement
  2. LB2064

    LB2064 New Member

    Joined:
    Feb 11, 2011
    Messages:
    4
    Likes Received:
    0
    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

    Joined:
    Jul 13, 2010
    Messages:
    1,934
    Likes Received:
    458
    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

Loading...