1. Download our Official Android App: Forums for Android!

Apps check Internet connectivity

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

  1. zalani

    zalani Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    8
    Joined:
    Feb 2, 2012

    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 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Feb 11, 2011

    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 Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    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...