If (isConnect (this) = false ){
New AlertDialog. Builder (
This)
. SetTitle ("network error ")
. SetMessage (
"Network connection failed,
Confirm network connection ")
. SetPositiveButton (
"OK ",
New www.2cto.com
DialogInterface. OnClickListener (){
@ Override
Public
Void onClick (
DialogInterface 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) {// note that this judgment is required.
Otherwise, an error occurs.
Return networkInfo
. IsAvailable ();
}
Return false;
}
-------------- Manifest. xml
<Uses-permission android: name = "android. permission. INTERNET"/>
<Uses-permission android: name = "android. permission. ACCESS_NETWORK_STATE"/>
By gongzibai