Android API-23: InetAddressUtils replacement

后端 未结 5 1989
误落风尘
误落风尘 2020-12-30 01:07

Switching to Android Marshmallow API, I was using org.apache.http.conn.util.InetAddressUtils for InetAddressUtils.isIPv4Address(ipAddress) in a cod

5条回答
  •  爱一瞬间的悲伤
    2020-12-30 01:36

    Like I interprete from the comments you can replace that function with this comparison:

    inetAddress instanceof Inet4Address
    

    so your code would end in:

    if(!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
    

    Update from 2020
    Keep in mind that your user can also have IPv6 enabled. In that case you need to check for Inet6Address too.

提交回复
热议问题