### 首先要加个权限
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" >
</uses-permission>
### 判断网络是否可用
public boolean isNetWorkAvailable(Context context) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (manager != null) {
NetworkInfo info = manager.getActiveNetworkInfo();
if (info != null && info.isConnected()) {
return true;
} else {
return false;
}
} else {
return false;
}
}