Check the connectivity status in android

Many of web based applications, check the internet connections, before done the web services.

You can set the permission for network state, like this

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

Code:

public boolean networkAvailability() {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}

}
return false;
}


Comments

Popular posts from this blog

Clear the app data programmatically in android

convert an integer to a string in java

Print the large string values in android log cat.