Android WIFI IP

private String getLocalIpAddress() {
    WifiManager wifiManager = getSystemService(WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    // 获取32位整型IP地址
    int ipAddress = wifiInfo.getIpAddress();

    //返回整型地址转换成“*.*.*.*”地址
    return String.format("%d.%d.%d.%d",
            (ipAddress & 0xff), (ipAddress >> 8 & 0xff),
            (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));
}
展开阅读全文

没有更多推荐了,返回首页