Formatter.formatIpAddress(int)的替代方法; [英] Alternative for Formatter.formatIpAddress(int);

查看:52
本文介绍了Formatter.formatIpAddress(int)的替代方法;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用了此代码,但警告内容如下:不赞成使用Formatter类型的formatIpAddress(int)方法"

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());

什么是快速解决方案?

推荐答案

文档说明

使用getHostAddress(),它同时支持IPv4和IPv6地址.此方法不支持IPv6地址.

Use getHostAddress(), which supports both IPv4 and IPv6 addresses. This method does not support IPv6 addresses.

其中 getHostAddress()是指 InetAddress.getHostAddress() .

但是, WifiInfo 仅有一个ipv4地址作为 int 和AFAIK,没有实用的方法将其转换为 InetAddress .弃用是因为该功能不支持ipv6,但 WifiInfo 也不支持.所以我只说使用 formatIpAddress(),因为它可以工作,并添加 @SuppressWarnings("deprecation")以消除警告.

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.

这篇关于Formatter.formatIpAddress(int)的替代方法;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆