일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 앱 기획
- 공학인증
- 기술인증
- flutter progress dialog
- Android
- flutter
- game engine
- c
- HTML 게임 엔진
- 블러 효과
- 맨붕
- 플러터
- rotate circle
- reverse proxy
- PowerMockup
- c++
- progress
- BlurDrawable
- first flutter app
- OpenGL
- Engineer Australia
- ABEEK
- nginx
- quintus
- StatelessWidget
- StatefulWidget
- ipad
- 호주 이민
- first_app
- 회전판
Archives
- Today
- Total
우동우동우's note
Android 4.0 get local IP Address 본문
과거에 인터넷에서 로컬 IP 주소를 받아오는 메서드를 인터넷에서 검색하여 한동안 잘 사용하고 있었다.
그런데 4.0에서 갑자기... 안되는.. 황당한 시츄에이션...
다시 잘 살펴보니 IPv6 형태의 주소를 가져 오고 있었다.
그래서 아래와 같이 메서드에 약간의 수정을 하여서 IPv4 형태의 IP 주소를 가져오게 하였다.
public final static int TYPE_INET4ADDRESS = 1; public final static int TYPE_INET6ADDRESS = 2; public static String getLocalIpAddress(int type) { try { for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = ( NetworkInterface ) en.nextElement(); for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = ( InetAddress ) enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { switch (type) { case TYPE_INET6ADDRESS: if (inetAddress instanceof Inet6Address) { return inetAddress.getHostAddress().toString(); } break; case TYPE_INET4ADDRESS: if (inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress().toString(); } break; } } } } }catch (Exception e) { } return null; }
'Java & Android' 카테고리의 다른 글
Android Sectioned ListView (2) | 2013.02.08 |
---|---|
[Android] Fragment 안에 MapView 넣기 (2) | 2012.08.08 |
[Android] Caused by: java.lang.ClassNotFoundException: com.google.android.maps.MapView (0) | 2012.08.07 |
Eclipse SVN 설치 (0) | 2012.07.06 |
안드로이드 빌드 시작 (0) | 2012.07.06 |
Comments