달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
728x90
반응형

안드로이드 - Android Device IP받아오기

2011/11/30 11:06

복사 http://blog.naver.com/ijoos/60148502173

private String getLocalAddress()throws IOException {


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();
// return inetAddress;
}
}
}
} catch (SocketException ex) {
}
return "";
}


와 같이 이용하면 됩니다. 어떤 기기는 안되고 되고 한다고 하니까 예외처리를 해야 겠지요?....

728x90
반응형
:
Posted by mapagilove