这是我的networkCheckIn()函数,它连续返回 false 。我无法调试这个。请给我一些解决方案
networkCheckIn()代码:
public boolean networkCheckIn(){
try{
ConnectivityManager networkInfo = (ConnectivityManager) getSystemService(MapViewActivity.CONNECTIVITY_SERVICE) ;
networkInfo.getActiveNetworkInfo().isConnectedOrConnecting() ;
Log.d("1", "Net avail:"
+ networkInfo.getActiveNetworkInfo().isConnectedOrConnecting());
ConnectivityManager cm = (ConnectivityManager) getSystemService(MapViewActivity.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
Log.d("2", "Network available:true");
return true;
} else {
Log.d("3", "Network available:false");
return false;
}
}catch(Exception e){
return false ;
}
}
函数调用:
if(!(gps.networkCheckIn() == true)){
gps.showSettingsAlert("Network", "Network") ;
}
我在Menifest.xml文件中使用了这两个权限:
uses-permission android:name =“android.permission.INTERNET”
uses-permission android:name =“android.permission.ACCESS_NETWORK_STATE”
我在手机和模拟器上试过了。它返回false,结果显示互联网的设置;互联网是启用还是禁用。