Issue
I'd used this code in my application, but the warning says its : "The method formatIpAddress(int) from the type Formatter is deprecated"
android.text.format.Formatter.formatIpAddress(mWifiManager.getConnectionInfo().getIpAddress());
what's the quick fix for this?
Solution
Use getHostAddress(), which supports both IPv4 and IPv6 addresses. This method does not support IPv6 addresses.
where getHostAddress()
refers to InetAddress.getHostAddress()
.
However, WifiInfo
just has a ipv4 address as an int
and AFAIK there's no practical way to convert it to an InetAddress
. The deprecation is because the function doesn't support ipv6 but neither does WifiInfo
. So I'd say just use formatIpAddress()
because it works and add @SuppressWarnings("deprecation")
to get rid of the warning.
Answered By - laalto
Answer Checked By - David Marino (JavaFixing Volunteer)