我将尝试使用下面的方法来检查Android的互联网连接。我有一个WIFI连接
i am trying to check internet connectivity in android using the following method. I have a WIFI connection
private boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
// test for connection
if (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected()) {
return true;
} else {
//no conection
return false;
}
}
我断开互联网我的电脑,然后尝试运行上面的方法。不过它总是!?返回true救命啊!
I disconnect my PC from the internet and then try to run the above method. Still it always returns true!? Help!
要禁用Internet连接
To Disable Internet Connection
进入到Eclipse
Go to Eclipse
Window->show view->other->android->Devices
现在选择你的运行模拟器,并再次
now select your running emulator and Again
进入,
Window->show view->other->android->Emulator Control
现在在.. 一组数据,以注销从首页
在设备或模拟器进入,
Setting -> Wireless & networks -> Airplane Mode -> ok