首页 > 移动平台 > 详细

android 判断网络连接的工具类

时间:2015-10-15 22:00:52      阅读:268      评论:0      收藏:0      [点我收藏+]

  

 1 package com.way.util;
 2 
 3 import android.content.Context;
 4 import android.net.ConnectivityManager;
 5 import android.net.NetworkInfo.State;
 6 
 7 public class NetUtil {
 8     public static final int NETWORN_NONE = 0;
 9     public static final int NETWORN_WIFI = 1;
10     public static final int NETWORN_MOBILE = 2;
11 
12     public static int getNetworkState(Context context) {
13         ConnectivityManager connManager = (ConnectivityManager) context
14                 .getSystemService(Context.CONNECTIVITY_SERVICE);
15 
16         // Wifi
17         State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
18                 .getState();
19         if (state == State.CONNECTED || state == State.CONNECTING) {
20             return NETWORN_WIFI;
21         }
22 
23         // 3G
24         state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
25                 .getState();
26         if (state == State.CONNECTED || state == State.CONNECTING) {
27             return NETWORN_MOBILE;
28         }
29         return NETWORN_NONE;
30     }
31 }

 

android 判断网络连接的工具类

原文:http://www.cnblogs.com/Sunnor/p/4883609.html

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