android设备获取当前所用网络类型和获取手机ip地址
来源:互联网 发布:55开和笑笑 知乎 编辑:程序博客网 时间:2024/06/08 10:31
* 得到当前的手机网络类型
*
* @param context
* @return
*/
public static String getCurrentNetType(Context context) {
String type = "";
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info == null) {
type = "null";
} else if (info.getType() == ConnectivityManager.TYPE_WIFI) {
type = "wifi";
} else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
int subType = info.getSubtype();
if (subType == TelephonyManager.NETWORK_TYPE_CDMA || subType == TelephonyManager.NETWORK_TYPE_GPRS
|| subType == TelephonyManager.NETWORK_TYPE_EDGE) {
type = "2g";
} else if (subType == TelephonyManager.NETWORK_TYPE_UMTS || subType == TelephonyManager.NETWORK_TYPE_HSDPA
|| subType == TelephonyManager.NETWORK_TYPE_EVDO_A || subType == TelephonyManager.NETWORK_TYPE_EVDO_0
|| subType == TelephonyManager.NETWORK_TYPE_EVDO_B) {
type = "3g";
} else if (subType == TelephonyManager.NETWORK_TYPE_LTE) {// LTE是3g到4g的过渡,是3.9G的全球标准
type = "4g";
}
}
LogProxy.d("QZY", "type=" + type);
return type;
}
/**
* 获取手机ip地址
*
* @return
*/
public static String getPhoneIp() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
// if (!inetAddress.isLoopbackAddress() && inetAddress
// instanceof Inet6Address) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (Exception e) {
}
return "";
}
转载自:http://www.open-open.com/lib/view/open1409190432572.html
- android设备获取当前所用网络类型和获取手机ip地址
- 获取手机网络类型和IP地址
- 获取手机网络类型和IP地址
- android 获取手机上面的IMSI序列号,IMEI,MAC地址,IP地址,当前时间,当前经纬度,获取网络类型
- 获取android手机当前ip地址
- 获取手机当前ip地址
- Android获取如何获取当前手机IP地址
- Android 手机上获取手机当前上网IP地址
- android 获取设备IP和Mac地址
- android 获取设备IP和Mac地址
- Android获取当前设备有效的IP地址
- Android 手机获取当前IP
- 获取iOS设备当前ip地址
- 获取iOS设备当前ip地址
- 获取iOS设备当前ip地址
- 获取 iOS 设备当前 ip 地址
- IOS 获取当前设备IP地址
- 获取iOS设备当前ip地址
- openCV 图像滤波
- leetcode || 116、Populating Next Right Pointers in Each Node
- 动态代理不通过接口,CGLIB动态代理
- 用Unity 3D生成真实地形
- CSS float 浮动属性
- android设备获取当前所用网络类型和获取手机ip地址
- 【cocos2d-x 7】介绍两本关于cocos2d-x开发的书籍
- R语言绘图设备
- 禅道,然之和蝉知入驻VM Depot
- [刷题]Partition List
- phoneGap在iOS上的简单使用:自定义实现友盟分享插件
- 《编写可维护的javascript》
- eclipse中出现Type 'xxxx' could not be resolved的处理方法
- 构建根文件系统一之ubuntu12.04下安装编译BusyBox图文解说