I am and trying to get an IP address of a mobile connection (the
emulator) with code.  I will be using it later in the code, but I only
know how to how to get the IP of wifi.


Below is what I am trying now, but it comes back null.  Does the
emulator just not able to get an IP or am I messing the code below
up?  I tried looking at the logcat, but no errors.


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(TAG, ex.toString());
                }
                return null;
            }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to