本宫不好惹,疯狂鉴黄师答案,冀星高速
android 网路判断
判断当前网络是否是wifi
/** * 判断当前是否是wifi * @param mcontext * @return */ private static boolean iswifi(context mcontext) { connectivitymanager connectivitymanager = (connectivitymanager) mcontext .getsystemservice(context.connectivity_service); networkinfo activenetinfo = connectivitymanager.getactivenetworkinfo(); if (activenetinfo != null && activenetinfo.gettype() == connectivitymanager.type_wifi) { return true; } return false; } }
一、判断网络连接是否可用
public static boolean isnetworkavailable(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; }
二、判断gps是否打开
public static boolean isgpsenabled(context context) { locationmanager lm = ((locationmanager) context .getsystemservice(context.location_service)); list<string> accessibleproviders = lm.getproviders(true); return accessibleproviders != null && accessibleproviders.size() > 0; }
三、判断wifi是否打开
public static boolean iswifienabled(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); }
四、判断是否是3g网络
public static boolean is3rd(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; }
五、判断是wifi还是3g网络,用户的体现性在这里了,wifi就可以建议下载或者在线播放。
public static boolean iswifi(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 apk 项目一键打包并上传到蒲公英的实现方法
Android 自定义LineLayout实现满屏任意拖动功能的示例代码
android 限制某个操作每天只能操作指定的次数(示例代码详解)
Android 集成 google 登录并获取性别等隐私信息的实现代码
网友评论