|
|
|
@ -54,21 +54,19 @@ public class DeviceUtil { |
|
|
|
} |
|
|
|
return ip; |
|
|
|
}else { |
|
|
|
String allIP = ""; |
|
|
|
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) { |
|
|
|
NetworkInterface intf = en.nextElement(); |
|
|
|
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) { |
|
|
|
InetAddress inetAddress = enumIpAddr.nextElement(); |
|
|
|
allIP += inetAddress.getHostAddress() + "\n"; |
|
|
|
if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress()) |
|
|
|
if (!inetAddress.isLoopbackAddress() && !inetAddress.isLinkLocalAddress() && inetAddress instanceof Inet4Address) { |
|
|
|
return inetAddress.getHostAddress(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Throwable t) { |
|
|
|
LoggerUtil.e("getLocalIP", StringUtil.getThrowableStr(t)); |
|
|
|
} |
|
|
|
|
|
|
|
return getLocalIPByWIFI(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -120,9 +118,10 @@ public class DeviceUtil { |
|
|
|
try { |
|
|
|
//获取wifi服务
|
|
|
|
WifiManager wifiManager = (WifiManager) MyApplication.getInstance().getApplicationContext().getSystemService(Context.WIFI_SERVICE); |
|
|
|
//判断wifi是否开启
|
|
|
|
if (!wifiManager.isWifiEnabled()) wifiManager.setWifiEnabled(true); |
|
|
|
WifiInfo wifiInfo = wifiManager.getConnectionInfo(); |
|
|
|
if (wifiInfo == null || wifiInfo.getIpAddress() == 0) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
int ipAddress = wifiInfo.getIpAddress(); |
|
|
|
ip = intToIp(ipAddress); |
|
|
|
} catch (Throwable t) { |
|
|
|
|