04工具类判断网络是否可用的方法和全局Constant类
来源:互联网 发布:耽美网络剧不可抗力 编辑:程序博客网 时间:2024/06/18 10:20
判断网络是否可用的方法:
package com.dy.ustc.im.utils;import android.content.Context;import android.net.ConnectivityManager;import android.net.NetworkInfo;/** * * 工具类 * * */public class CommonUtils {public static boolean isNetWorkConnected(Context context) {// 解决空指针异常if (context != null) {ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo networkInfo = mConnectivityManager.getActiveNetworkInfo();if (networkInfo != null) {return networkInfo.isAvailable();}}return false;}}
注意获取网络连接管理器和前面获取包管理器的方式,然后再获取相应的info。
package com.dy.ustc.im;public class Constant {public static final String NEW_FRIENDS_USERNAME = "item_new_friends";public static final String GROUP_USERNAME = "item_groups";public static final String MESSAGE_ATTR_IS_VOICE_CALL = "is_voice_call";}
0 0
- 04工具类判断网络是否可用的方法和全局Constant类
- ios 判断网络是否可用工具类
- 判断网络是否可用的方法
- 判断网络是否可用的方法
- Android判断网络是否可用的方法
- 工具类——网络是否可用
- Android--用ping的方法判断当前网络是否可用
- android判断网络是否可用方法
- android 判断是否有网络 方法 工具类里的几个常用方法
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- java tomcat部署
- ubuntu 截图工具-alt+ctrl+A
- Ubuntu 14.04 以root账户登陆
- ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序--解决方法
- Linux进程间通信: 消息队列
- 04工具类判断网络是否可用的方法和全局Constant类
- MFC中的GDI绘图(4)
- Android 网络交互(五) Socket 小论
- ffmpeg接口函数介绍(续2)
- 把char *的数据转换成图片
- HDU1395_2^x mod n = 1【数论】【水题】
- java for android 入门一
- Oracle数据库-where, group by, having, order by语句的执行顺序
- java学习--Properties类的使用