public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i <= info.length; i++) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
/**
* 检测网络是否存在 */
public boolean NetWortTest() {
if (!isNetworkAvailable()) {
Context context = getApplicationContext();
AlertDialog.Builder builders = new AlertDialog.Builder(context);
builders.setTitle("抱歉,暂时无法处理您的请求");
LayoutInflater _inflater = LayoutInflater.from(context);
View convertView = _inflater.inflate(0, null);
builders.setView(convertView);
builders.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builders.show();
return false;
} else {
return true;
}
}
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i <= info.length; i++) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
/**
* 检测网络是否存在 */
public boolean NetWortTest() {
if (!isNetworkAvailable()) {
Context context = getApplicationContext();
AlertDialog.Builder builders = new AlertDialog.Builder(context);
builders.setTitle("抱歉,暂时无法处理您的请求");
LayoutInflater _inflater = LayoutInflater.from(context);
View convertView = _inflater.inflate(0, null);
builders.setView(convertView);
builders.setPositiveButton("确定",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builders.show();
return false;
} else {
return true;
}
}