网络连接总是发现在手机上,即使没有网络 [英] network connection always detected on handset, even with no network
问题描述
我检查Android中的网络连接,在一个真正的手机。它总是显示Internet连接present,甚至当我关闭网络连接设置 - >位置 - >使用的无线网络 - >关闭和启用GPS statelites - >关闭,并且禁用无线
I am checking the networking connection in Android, on a real handset. It always shows "Internet Connection Present", even when I close the network connection in "Settings -> Location -> Use wireless network -> off" and "enable GPS statelites -> off" and also disable wifi.
我使用下面的code:
I am using the following code:
private boolean checkInternetConnection() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
// test for connection
if (cm.getActiveNetworkInfo() != null
&& cm.getActiveNetworkInfo().isAvailable()
&& cm.getActiveNetworkInfo().isConnected()) {
Log.e("TAG", "Internet Connection Present");
return true;
} else {
Log.e("TAG", "Internet Connection Not Present");
return false;
}
}
我已经设置权限:
I have set permissions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
我是什么做错了吗?
What am I doing wrong?
推荐答案
设置 - >位置 - >使用无线网络(关闭),并使用GPS卫星(关闭)如上述提到的设置来确定位置,而不是禁止访问到互联网。
'Settings->Location->Use wireless network (off) and Use GPS satellites (off)' as mentioned above are settings for determining location, not disabling access to the internet.
为了切断接入互联网完全,尽量飞行模式(设置 - >无线和网络设置 - >飞行模式)
In order to cut off access to the internet completely, try Airplane mode (Settings -> Wireless & network settings -> Airplane mode)
这篇关于网络连接总是发现在手机上,即使没有网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!