Android examples for java.net:IP Address
Convert int value ip Address To String
import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteOrder; import android.util.Log; public class Main{ public static String ipAddressToString(int ipAddress) { if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ipAddress = Integer.reverseBytes(ipAddress); }//from w ww . j a v a 2s .c om byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray(); String ipAddressString; try { ipAddressString = InetAddress.getByAddress(ipByteArray) .getHostAddress(); } catch (UnknownHostException ex) { Log.e("WIFI_IP", "Unable to get host address."); ipAddressString = "NaN"; } return ipAddressString; } }