androidandroid-5.0-lollipopnetmask

DhcpInfo isn't responding the netmask in Android Lollipop


Yesterday I update my nexus 5 to lollipop and my application stops working, after a little investigation I found the problem the DhcpInfo isn't is returning null on the netmask variable.

I couldn't find any alternative to this class.


Solution

  • You can use getNetworkPrefixLength method of InterfaceAddress, which you get from NetworkInterface. It returns the correct value in Lollipop.

    NetworkInterface networkInterface = NetworkInterface.getByInetAddress(ipAddress);
    for (InterfaceAddress address : networkInterface.getInterfaceAddresses()) {
        short netPrefix = address.getNetworkPrefixLength());
    }
    

    Note: It returns network prefix length, so you'd have to convert it (/24 for 255.255.255.0 etc.)