Android中判断网络是否连接实例详解
更新时间:2017年01月24日 10:13:45 投稿:lqh
这篇文章主要介绍了Android中判断网络是否连接实例详解的相关资料,需要的朋友可以参考下
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(); //
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关文章
Flutter 弹性布局基石flex算法flexible示例详解
这篇文章主要为大家介绍了Flutter 弹性布局基石flex算法flexible示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2022-12-12开源电商app常用标签"hot"之第三方开源LabelView
这篇文章主要介绍了开源电商app常用标签"hot"之第三方开源LabelView,对开源电商app相关资料感兴趣的朋友一起学习吧2015-12-12Android中使用ScrollView指定view的顶部悬停效果
在项目开发中遇到这样的需求,需要实现scrollview顶部的悬停效果,实现原理非常简单,下面小编通过本文给大家分享实例代码,需要的朋友参考下2017-04-04Android 出现“Can''t bind to local 8602 for debugger”错误的解决方法
这篇文章主要介绍了Android 出现“Can't bind to local 8602 for debugger”错误的解决方法的相关资料,需要的朋友可以参考下2017-03-03Android编程实现点击EditText之外的控件隐藏软键盘功能
这篇文章主要介绍了Android编程实现点击EditText之外的控件隐藏软键盘功能,涉及Android控件的功能、属性及相关操作技巧,需要的朋友可以参考下2017-06-06
最新评论