有什么办法如何利用ContentProvider的检查,我的Android手机是否连接到互联网?
感谢
解决方案 //检查互联网连接
公共静态布尔isNetworkAvailable(上下文的背景下){
布尔networkStatus;尝试{ ConnectivityManager connectivityManager =(ConnectivityManager)上下文 .getSystemService(Context.CONNECTIVITY_SERVICE); 的NetworkInfo activeNetworkInfo = connectivityManager .getActiveNetworkInfo(); networkStatus =(activeNetworkInfo = NULL&放大器;!&安培; activeNetworkInfo.isConnected())?真假;}赶上(例外五){ e.printStackTrace(); DinotaLogger.log(即Level.SEVERE); networkStatus = FALSE;}返回networkStatus;
}
请确保把清单文件。如果你正在使用模拟器来检查这一点,preSS F8禁用网络访问。这工作得很好了Android 2.3.3模拟器
is there any way how to take advantage of ContentProvider to check, whether my Android phone is connected to the internet?
Thanks
解决方案// check internet connectivity
public static boolean isNetworkAvailable(Context context) {
boolean networkStatus;
try {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager
.getActiveNetworkInfo();
networkStatus = (activeNetworkInfo != null && activeNetworkInfo.isConnected()) ? true : false;
} catch (Exception e) {
e.printStackTrace();
DinotaLogger.log(e, Level.SEVERE);
networkStatus = false;
}
return networkStatus;
}
Please make sure to put in manifest file. If you are using an emulator to check this, press F8 to disable network access. This works fine with android 2.3.3 emulator