我可以通过此代码阅读ipv4
public String getLocalIpAddress() {
String ipaddress = null;
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.isLinkLocalAddress() && inetAddress.isSiteLocalAddress() ) {
if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(inetAddress.getHostAddress()) ) {
ipaddress = inetAddress.getHostAddress();
}
}
}
} catch (SocketException ex) {
// Log.d(TAG, ex.toString());
}
return ipaddress;
}
但我无法改变它。有没有办法通过代码更改静态IP?我只能在设置配置以太网设备菜单上更改它