zoukankan      html  css  js  c++  java
  • android 检测网络是否可用

    /**
         * 检测网络是否可用
         *
         * @return
         */
        public boolean isNetworkConnected() {
            ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo ni = cm.getActiveNetworkInfo();
            return ni != null && ni.isConnectedOrConnecting();
        }

        /**
         * 获取当前网络类型
         *
         * @return 0:没有网络 1:WIFI网络 2:WAP网络 3:NET网络
         */
        public int getNetworkType() {
            int netType = 0;
            ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
            if (networkInfo == null) {
                return netType;
            }
            int nType = networkInfo.getType();
            if (nType == ConnectivityManager.TYPE_MOBILE) {
                String extraInfo = networkInfo.getExtraInfo();
                if (!StringUtils.isEmpty(extraInfo)) {
                    if (extraInfo.toLowerCase().equals("cmnet")) {
                        netType = NETTYPE_CMNET;
                    } else {
                        netType = NETTYPE_CMWAP;
                    }
                }
            } else if (nType == ConnectivityManager.TYPE_WIFI) {
                netType = NETTYPE_WIFI;
            }
            return netType;
        }

  • 相关阅读:
    【总结整理】javascript的函数在if中调用时是否加括号---与.net的不同之处
    【总结整理】javascript的函数调用时是否加括号
    【总结整理】JavaScript的DOM事件学习(慕课网)
    关于overflow:hidden (转)
    CSS
    HTML
    jQuery
    函数
    装饰器
    python的条件与循环1
  • 原文地址:https://www.cnblogs.com/luomingui/p/3949442.html
Copyright © 2011-2022 走看看