写了一个函数用来判断手机是否连接网络,如下:
public static boolean IsHaveInternet(final Context context){
try{
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
if(info.isConnected()||wifiManager.isWifiEnabled()){
return true;
}else{
return false;
}
}catch(Exception e){
return false;
}
}
然后调用,在logcat里输出这个值,结果输出的总是上面catch里面的返回值,catch里是啥,输出的就是啥,怎么回事
boolean pd = IsHaveInternet(this);
System.out.println("pddaosi是:"+pd);
public static boolean IsHaveInternet(final Context context){
try{
ConnectivityManager manager = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
if(info.isConnected()||wifiManager.isWifiEnabled()){
return true;
}else{
return false;
}
}catch(Exception e){
return false;
}
}
然后调用,在logcat里输出这个值,结果输出的总是上面catch里面的返回值,catch里是啥,输出的就是啥,怎么回事
boolean pd = IsHaveInternet(this);
System.out.println("pddaosi是:"+pd);