android 网络连接的判断
来源:互联网 发布:win7与linux双系统 编辑:程序博客网 时间:2024/06/07 04:05
网络连接判断的工具类,判断是wifi网络, 还是蜂窝网络,或者无网络;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* author:Created by WangZhiQiang on 2017-09-05.
*/
public class Utils {
/**
* 返回值 -1:没有网络 1:WIFI网络 2:net网络
*/
public static int getNetype(Context context) {
int netType = -1;
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
netType = 2;
} else if (nType == ConnectivityManager.TYPE_WIFI) {
netType = 1;
}
return netType;
}
}
package com.wzq.wifidemo;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
/**
* author:Created by WangZhiQiang on 2017-09-05.
*/
public class Utils {
/**
* 返回值 -1:没有网络 1:WIFI网络 2:net网络
*/
public static int getNetype(Context context) {
int netType = -1;
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo == null) {
return netType;
}
int nType = networkInfo.getType();
if (nType == ConnectivityManager.TYPE_MOBILE) {
netType = 2;
} else if (nType == ConnectivityManager.TYPE_WIFI) {
netType = 1;
}
return netType;
}
}
阅读全文
0 0
- Android网络连接的判断
- android网络连接的判断
- android网络连接的判断
- Android的网络连接判断
- android 网络连接的判断
- Android网络连接的判断
- android 网络连接的判断
- android 网络连接的判断
- android 网络连接的判断
- Android 网络连接的判断
- android 网络连接的判断
- android 网络连接的判断
- android 网络连接的判断
- android 网络连接的判断
- android 判断网络连接
- android 判断网络连接
- android 判断网络连接
- android 判断网络连接
- 判断
- 壕!程序员摆25台iPhone X求婚 闺蜜1人1台
- uva 1630 KMP判断周期串 和 区间DP 压缩字符串
- Git常用操作,最常用的都在这了
- 判断
- android 网络连接的判断
- android 之MVP模板
- 石子合并
- 防止用户误操作Back键
- 2017-11-3 Linux盘格式化、挂载、手动增加swap空间
- css创建表格
- CentOS 7 安装Python3以及pip3
- 如何在Android的XML文件中添加注释 本文转载自http://blog.csdn.net/pipisorry/article/details/24833325,感谢原创大神!
- Struts2的多文件上传 和 单文件下载