2014-05-19 6 views
0

나는 안드로이드에 새로운 오전과 내가있는 내가 이제 다음 코드Android - Dhcp에서 인터넷 속성을 포맷하는 방법

try{ 
    WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE); 
    WifiInfo wi = wm.getConnectionInfo(); 
    String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress()); 
    TextView ipAddressText = (TextView)findViewById(R.id.productInfo_lanIpAddress); 
    ipAddressText.setText(ip); 
    DhcpInfo dInfo = wm.getDhcpInfo(); 

    ip = String.valueOf(dInfo.gateway); 
    TextView defaultGateway = (TextView)findViewById(R.id.productInfo_defaultGateway); 
     defaultGateway.setText(ip); 
    }//*/ 
    catch (Exception ex) { 
     TextView ipAddressText = (TextView)findViewById(R.id.productInfo_lanIpAddress); 
     ipAddressText.setText(ex.toString()); 

    } 
    /* 

를 사용하여 IP 주소를 가지고 나는 내가 생각 LAN IP 주소, 서브넷 마스크, 기본 게이트웨이 및 기타 정보를 표시하고 응용 프로그램을 만드는 오전 기본 게이트웨이를 받고 있지만 그것이 제대로 표시되지 않도록 번호가 형식화되어 있습니다 (내가 16885352를 얻고 있습니다) Formatter와 같은 방식으로 IP 주소를 형식화 했습니까? 다른 인터넷 정보에서도 동일한 효과를 얻는 방법에 대한 링크 또는 가이드를 얻고 싶습니다. 감사합니다.

답변

0

좋아요. 그래서 우리가 IP 주소를 얻는 방법과 비슷하게 달성되는 방법을 발견했습니다. 즉, Formatter.formatIpAddress()를 사용하여 적절한 서브넷 마스크, 기본 게이트웨이, 기본 DNS 및 보조 DNS를 가져옵니다. 같은 형식으로되어 있기 때문에 나타납니다. 건배!

0

getIpAddress 메소드는 IP의 int 표현을 리턴합니다. exemple를 들어 다음과 같은 IP : 172.16.254.1 가에 진

10101100 00010000 11111110 00000001 
    172  16  254  1 

때문에 등가 INT는 2886794753. 당신은 같은 것을 사용할 수있는 IP 주소의 문자열 표현으로 변환하는 것입니다

public String intToIp(int i) { 
    return ((i >> 24) & 0xFF) + "." + 
      ((i >> 16) & 0xFF) + "." + 
      ((i >> 8) & 0xFF) + "." + 
      (i & 0xFF) ; 
} 

안드로이드 설명서에이 정보가 없습니다.