有没有简单的方法,如何检查设备是否已主动连接到Internet(=已通过GPRS、EDGE、UMTS、HSDPA或Wi-Fi连接)?
谢谢
最佳答案
是的,我用的是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;
}
}
}
}