android 判断网络连接是否可用

 时间:2024-10-30 15:07:14

1、判断连接的工具类类名:Network_status

android 判断网络连接是否可用

2、/** * 判断网络连接是否可用 * @param context * @return */pu水瑞侮瑜bli艘早祓胂c static boolean is_Network_Available(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) { } else { //如果仅仅是用来判断网络连接 //则可以使用 cm.getActiveNetworkInfo().isAvailable(); NetworkInfo[] info = cm.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; }

android 判断网络连接是否可用

3、/** * 判断GPS是否打开 * @param context * @return */public static boolean is_Gps_Enabled(Context context) { LocationManager lm = ((LocationManager) context .getSystemService(Context.LOCATION_SERVICE)); List<String> accessibleProviders = lm.getProviders(true); return accessibleProviders != null && accessibleProviders.size() > 0; }

android 判断网络连接是否可用

4、/** * 判断WIFI是否打开 * @param context * @return */pu水瑞侮瑜bli艘早祓胂c static boolean is_Wifi_Enabled(Context context) { ConnectivityManager mgrConn = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager mgrTel = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); return ((mgrConn.getActiveNetworkInfo() != null && mgrConn .getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel .getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS); }

android 判断网络连接是否可用

5、/** * 判断是否是3G网络 * @param context * @return */public static boolean is_3rd(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkINfo = cm.getActiveNetworkInfo(); if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; } return false; }

android 判断网络连接是否可用

6、/** * 判断是wifi还是3g网络 * @param context * @return true(wifi) */public static boolean is_Wifi(Context context) { ConnectivityManager cm = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkINfo = cm.getActiveNetworkInfo(); if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } return false; }

android 判断网络连接是否可用
  • 封神异魔录正式版怎么转生
  • 怎么追到女朋友(女神)?
  • 全民猜成语第1~3关攻略
  • 2016新版百度商桥首次下载使用基础设置
  • 旧设备进口办理商务部自动进口许可证。
  • 热门搜索
    多喝水能减肥 纪念碑谷2攻略 苏州东山旅游攻略 海明威简介 二十一天减肥法 cad图怎么打印 跑步机减肥效果好吗 一周减肥 红头文件怎么做 桂林旅游攻略必去景点