0

Possible Duplicate:
How to get the Android Emulator's IP address?

i coded an android app to get data from a mysql database created on the pc where my android emulator in installated. What's the ip address I've to set into the http post request to get the access?

Thanks in advance

Community
  • 1
  • 1
FrankBr
  • 886
  • 2
  • 16
  • 37

1 Answers1

0

just Put these lines of codes to get the IP address of your current emulator.

public String getLocalIpAddress() {
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()) {
                return inetAddress.getHostAddress().toString();
            }
        }
    }
} catch (SocketException ex) {
    Log.e(LOG_TAG, ex.toString());
}
return null;
}

It will return the IP address of your Emulator in the for of the strings.

coading fever
  • 221
  • 2
  • 10