Android 判断wifi环境下局域网IP

概要:

Android 判断wifi环境下局域网IP

| |目录

public String getIpAddress(){
        WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        if (wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED)
        {
            WifiInfo info = wm.getConnectionInfo();
           int  hostip = info.getIpAddress();
           String ip = (hostip & 0xFF)+"."+((hostip>>8)&0xFF)+ "." + ((hostip >> 16 ) & 0xFF) +"."+((hostip >> 24 ) & 0xFF);
            Toast.makeText(MainActivity.this, ip, 1).show();
            return ip;
        }
        return null;
    }
评论关闭
评论 还能输入200
评论关闭
评论 还能输入200
资料加载中...
已关注 , 取消