Android-检查设备是否已连接到互联网
问题描述:
有什么简单的方法,如何检查设备是否已有效连接到Internet(=是否通过GPRS,EDGE,UMTS,HSDPA或Wi-Fi连接)?
is there any simple way, how to check if the device is actively connected into internet (= is connected via GPRS, EDGE, UMTS, HSDPA or Wi-Fi)?
谢谢
答
是的,我使用isReachable.
Yes, I use isReachable.
public class Extras {
public static class Internet {
public static boolean isOnline() {
try {
InetAddress.getByName("google.ca").isReachable(3);
return true;
} catch (UnknownHostException e){
return false;
} catch (IOException e){
return false;
}
}
}
}