check Internet connectivity

Discussion in 'Application Development' started by zalani, Feb 2, 2012.

  1. zalani

    zalani Member
    5

    Feb 2, 2012
    8
    0
    5
    Male
    Indore
    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
    5

    Feb 11, 2011
    4
    0
    5
    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
    163

    Jul 13, 2010
    1,934
    458
    163
    Male
    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...