Android中判断网络是否连接实例详解
2017-01-24 10:13
971 查看
Android中判断网络是否连接实例详解
在android中,如何监测网络的状态呢,这个有的时候也是十分重要的,方法如下:
public class ConnectionDetector { private Context _context; public ConnectionDetector(Context context){ this._context = context; } public boolean isConnectingToInternet(){ ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { NetworkInfo[] info = connectivity.getAllNetworkInfo(); if (info != null) for (int i = 0; i < info.length; i++) if (info[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } return false; }
调用:
ConnectionDetector cd = new ConnectionDetector(getApplicationContext()); Boolean isInternetPresent = cd.isConnectingToInternet(); //
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
相关文章推荐
- [Android实例] 判断网络是否连接,然后选择网络类型(比如wifi等)来连接网络
- php判断是否连接上网络的方法实例详解
- php判断是否连接上网络的方法实例详解
- Android(安卓)判断网络是否连接
- android 判断是否有网络连接,判断网络连接类型
- Android编程判断是否连接网络的方法【WiFi及3G判断】
- Android中判断应用运行时是否有网络连接并弹出对话框提示
- android 判断网络是否连接
- Android中判断是否连接到网络
- Android判断网络是否连接
- Android中判断网络连接是否可用及监控网络状态
- Android中判断网络连接是否可用及监控网络状态
- Android中判断网络连接是否可用及监控网络状态
- Android中判断网络连接是否可用及监控网络状态
- Android中判断网络是否处于连接状态
- Android 判断手机是否连接网络
- Android中判断网络连接是否可用及监控网络状态
- Android开发--判断网络是否连接
- 关于android 如何判断是否连接网络
- Android网络 ——判断网络是否连接