현재 진저와 ICS에서 사용되는 앱 개발의 마지막 단계에 있습니다.

 

그런데 지금 벽에 부딪혔습니다.

 

IP주소를 얻어오는 코드를 아래의 코드를 쓰는데요.

public final static int INET4ADDRESS = 1;

public final static int 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 INET6ADDRESS:

if (inetAddress instanceof Inet6Address) {

return inetAddress.getHostAddress().toString();

}

break;


case INET4ADDRESS:

if (inetAddress instanceof Inet4Address) {

return inetAddress.getHostAddress().toString();

}

break;

}

}

}

}

} catch (SocketException ex) {

}

return null;

}

 

만약 진저에서 동작할때는 4타입을 ICS에서 동작할때는 6타입을 읽어와야 하는데...

 

아이피 타입을 구하는 함수....아...?

 

자답입니다.

 

SDK버젼을 구해서 분기처리하면 될라나..;;;

 

혹시 좋은 방법이 있을까요?