太上道德天尊,强生婴儿油,最美伪娘分类目录
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 studio 解决logcat无过滤工具栏的操作
Android Studio 恢复小窗口停靠模式(Docked Mode)
Android studio保存logcat日志到本地的操作
Android Studio快捷键生成TAG、Log.x日志输出介绍
网友评论