Android开发笔记: Android获取Ip地址

版权声明:本文为博主原创文章,未经博主允许不得转载。http://blog.csdn.net/taoerit https://blog.csdn.net/taoerit/article/details/79975303
public  String getLocalIpAddress() {
    
    //获取wifi服务
    WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    //判断wifi是否开启
    if (!wifiManager.isWifiEnabled()) {
        return "NULL";
    }
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    int ip = wifiInfo.getIpAddress();
    return  (ip & 0xFF ) + "." + ((ip >> 8 ) & 0xFF) + "." + ((ip >> 16 ) & 0xFF) + "." + ( ip >> 24 & 0xFF) ;
}
阅读更多
想对作者说点什么? 我来说一句

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