• Android 判断wifi和4G网络是否开启


        public boolean isWifiAvailable() {
            ConnectivityManager connectivityManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
            return (networkInfo != null && networkInfo.isConnected() && networkInfo
                    .getType() == ConnectivityManager.TYPE_WIFI);
        }
    
        /**
         * 判断当前网络是否是4G网络
         *
         * @param
         * @return boolean
         */
        public boolean is4GAvailable() {
            ConnectivityManager connectivityManager = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetInfo != null
                    && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
                TelephonyManager telephonyManager = (TelephonyManager)
                        getActivity().getSystemService(
                                Context.TELEPHONY_SERVICE);
                int networkType = telephonyManager.getNetworkType();
                /** Current network is LTE */
                if (networkType == 13) {
                    /**此时的网络是4G的*/
                    return true;
                }
            }
            return false;
        }
  • 相关阅读:
    第三周学习进度条
    软件工程个人作业02
    构建之法阅读笔记02
    学习进度条
    构建之法阅读笔记01
    软件工程个人作业01
    构建之法粗读
    第一次作业
    动手动脑接口与继承
    大道至简第七章第八章
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/5670447.html
Copyright © 2020-2023  润新知