判断 ip 是否为wifi
简介:
引用:http://www.oschina.net/code/snippet_54100_5507
//获取本地ip地址
47
48
public String getLocalIpAddress() {
49
try {
50
Enumeration en = NetworkInterface.
引用:http://www.oschina.net/code/snippet_54100_5507
48 |
public String getLocalIpAddress() { |
50 |
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); |
51 |
while (en.hasMoreElements()) { |
52 |
NetworkInterface intf = en.nextElement(); |
53 |
Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); |
54 |
while (enumIpAddr.hasMoreElements()) { |
55 |
InetAddress inetAddress = enumIpAddr.nextElement(); |
56 |
if (!inetAddress.isLoopbackAddress()) { |
57 |
return inetAddress.getHostAddress().toString(); |
61 |
} catch (SocketException ex) { |
73 |
public static boolean isWifi(Context mContext) { |
74 |
ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); |
75 |
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); |
76 |
if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) { |