Android-检查设备是否已连接到互联网 [英] Android - checking if the device is connected to the internet

查看:63
本文介绍了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;
            }
        }
    }
}

这篇关于Android-检查设备是否已连接到互联网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆