• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps check Internet connectivity

zalani

Lurker
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"/>
 
Is there an app that can check internet connectivity and give a notification in the status bar if internet connectivity is lost?
 
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).
 
Back
Top Bottom