首页 > 其他 > 详细

检查网络是否可用

时间:2014-07-30 14:45:03      阅读:346      评论:0      收藏:0      [点我收藏+]
/**
     * 检测网络是否可用1
     * @param act
     * @return
     */
    public boolean isNetConnected(Activity act){
            
            ConnectivityManager manager = (ConnectivityManager) act  
                   .getApplicationContext().getSystemService(  
                          Context.CONNECTIVITY_SERVICE);  
             
            if (manager == null) {  
                return false;  
            }  
            NetworkInfo networkinfo = manager.getActiveNetworkInfo();  
            if (networkinfo == null || !networkinfo.isAvailable()) {  
                return false;  
            }  
            return true;  
    }

/**
     * 检测网络是否可用2
     */
private boolean isNetConnected() {
        PppoeManager pppoeManager = PppoeManager.getInstance();
        EthernetManager ethernetManager = EthernetManager.getInstance();
        ConnectivityManager connectivityManager = (ConnectivityManager)
	 getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getNetworkInfo
	(ConnectivityManager.TYPE_WIFI);
        if (networkInfo.isConnected() || ethernetManager.isNetworkConnected()
                || pppoeManager.getPppoeStatus().equals
		(PppoeManager.PPPOE_STATE_CONNECT)) {
            return true;
        } else {
            return false;
        }
    }


检查网络是否可用,布布扣,bubuko.com

检查网络是否可用

原文:http://blog.csdn.net/only_tan/article/details/38300025

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!