
/** |
* check if the network is available |
* @param context |
* @return true if the network is available, false the other |
*/ |
public static Boolean NetworkState(Context context) { |
ConnectivityManager connectivity = (ConnectivityManager) context |
.getSystemService(Context.CONNECTIVITY_SERVICE); |
if (connectivity == null) { |
return false; |
} else { |
// Obtain all network connection information |
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; |
} |



