一个判断网络是否连接的工具类
来源:互联网 发布:it工作者 编辑:程序博客网 时间:2024/05/16 04:51
安卓判断网络是否连接,以下是代码:
public class NetUtil { /** * 检查当前手机网络 * * @param context * @return */ public static boolean checkNet(Context context) { // 判断连接方式 boolean wifiConnected = isWIFIConnected(context); boolean mobileConnected = isMOBILEConnected(context); if (wifiConnected == false && mobileConnected == false) { // 如果都没有连接返回false,提示用户当前没有网络 return false; } return true; } // 判断手机使用是wifi还是mobile /** * 判断手机是否采用wifi连接 */ public static boolean isWIFIConnected(Context context) { // Context.CONNECTIVITY_SERVICE). ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (networkInfo != null && networkInfo.isConnected()) { return true; } return false; } public static boolean isMOBILEConnected(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (networkInfo != null && networkInfo.isConnected()) { return true; } return false; }}
0 0
- 一个判断网络是否连接的工具类
- 判断网络是否连接工具类
- 封装工具类,判断是否连接网络,请求数据
- 检查网络是否连接的工具类
- 网络连接判断的工具类
- 一个网络判断的工具类
- 判断是否连接网络
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接,
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- 判断网络是否连接
- VMware虚拟机Mac OS X无法调整扩展硬盘大小的解决方案
- vim去除或替换^M字符
- Multi-class Classification
- N的阶乘HDOJ1042
- 爬虫之路——DAY1
- 一个判断网络是否连接的工具类
- 关于C#窗体中的三类坐标系
- hdu 3524 Perfect Squares(找规律,循环节,快速幂取模)
- JAVA中 byte[]数组如何转为InputStream
- CentOS7 修改网卡名称为eth0 & 在VMWare中添加多网卡配置
- Android 轻松实现仿淘宝地区选择
- Tachyon内存文件系统
- MySQL创建复合主键
- openSUSE vsftpd 搭建