Android 判断网络连接运用
if (isConnect(this) == false) {
new AlertDialog.Builder(
this)
.setTitle("网络错误")
.setMessage(
"网络连接失败,
请确认网络连接")
.setPositiveButton(
"确定",
new www.zzzyk.com
DialogInte易做图ce.OnClickListener() {
@Override
public
void onClick(
DialogInte易做图ce arg0,
int arg1) {
// TODO Auto-generated method stub
}
}).show();
}
private boolean isConnect(
Gongzibai gongzibai) {
ConnectivityManager conManager = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = conManager
.getActiveNetworkInfo();
if (networkInfo != null) { // 注意,这个判断一定要的哦
,要不然会出错
return networkInfo
.isAvailable();
}
return false;
}
--------------manifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
作者:gongzibai
补充:移动开发 , Android ,