Wednesday, August 17, 2011

network elerhetoseg ellenorzese Androidon

Lars Vogel-tol:

Android allows to check if the network is available. Here is a code snippet to check this:
public boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
// if no network is available networkInfo will be null, otherwise check if we are connected
if (networkInfo != null && networkInfo.isConnected()) {
return true;
}
return false;
}
Your application requires also the uses-permission “android.permission.ACCESS_NETWORK_STATE” to check for the network state.

No comments: