Umstellung auf Android Marshmallow API, ich war org.apache.http.conn.util.InetAddressUtils
für InetAddressUtils.isIPv4Address(ipAddress)
in einem Code, um alle IPs von einem Gerät aufzulisten.Android API-23: InetAddressUtils Ersatz
Als Teil der API-23 changes ist die InetAddressUtils
Klasse jetzt weg.
Wie kann ich den folgenden Code jetzt ersetzen?
public static String ipAddress() {
try {
for (final Enumeration<NetworkInterface> enumerationNetworkInterface = NetworkInterface.getNetworkInterfaces(); enumerationNetworkInterface.hasMoreElements();) {
final NetworkInterface networkInterface = enumerationNetworkInterface.nextElement();
for (Enumeration<InetAddress> enumerationInetAddress = networkInterface.getInetAddresses(); enumerationInetAddress.hasMoreElements();) {
final InetAddress inetAddress = enumerationInetAddress.nextElement();
final String ipAddress = inetAddress.getHostAddress();
if (! inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ipAddress)) {
return ipAddress;
}
}
}
return null;
}
catch (final Exception e) {
LogHelper.wtf(null, e);
return null;
}
}
Was möchten Sie tun? Wenn Sie nur wissen wollen, ob eine IP IPv6 ist oder nicht, können Sie nach 'inetAddress instanz von Inet6Address' oder 'inetAddress instance von Inet4Address' suchen. – rekire
Ich versuche, 'InetAddressUtils.isIPv4Address (ipAddress)' mit einem Code zu ersetzen, der mit Android API-23 funktioniert – shkschneider
Wie seine Namen sagt: zurück, wenn die IP-Adresse IPv4 oder nicht https://hc.apache.org/ httpcomponents-client-ga/httpclient/apidocs/org/apache/http/conn/util/InetAddressUtils.html # isIPv4Address (java.lang.String) Diese Methode ist jetzt in Android API-23 nicht verfügbar. Ich möchte es nur ersetzen, aber ich kenne noch keine Alternativen. – shkschneider