Posted By

cautionsign on 10/12/10


Tagged

ipAddress android


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

thastyle


Android get IP Address


 / Published in: Java
 

URL: http://androidcore.com/android-programming-tutorials/633-how-to-get-the-ip-address-of-your-android-device.html

  1. public String getLocalIpAddress() {
  2. try {
  3. for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
  4. NetworkInterface intf = en.nextElement();
  5. for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
  6. InetAddress inetAddress = enumIpAddr.nextElement();
  7. if (!inetAddress.isLoopbackAddress()) {
  8. return inetAddress.getHostAddress().toString();
  9. }
  10. }
  11. }
  12. } catch (SocketException ex) {
  13. Log.e(LOG_TAG, ex.toString());
  14. }
  15. return null;
  16. }

Report this snippet  

You need to login to post a comment.