/**
* 获取本地ip
* @return
*/
public String getLocalIpAddress()
{
String ipaddress = "";
try
{
Enumeration<NetworkInterface> en = NetworkInterface
.getNetworkInterfaces();
// 遍历所用的网络接口
while (en.hasMoreElements())
{
NetworkInterface nif = en.nextElement();// 得到每一
Enumeration<InetAddress> inet = nif.getInetAddresses();
// 遍历每一个接口绑定的所有ip
while (inet.hasMoreElements())
{
InetAddress ip = inet.nextElement();
if (!ip.isLoopbackAddress()
&& InetAddressUtils.isIPv4Address(ip
.getHostAddress()))
{
return ipaddress =ip.getHostAddress();
}
}
}
}
catch (SocketException e)
{
Log.e("feige", "获取本地ip地址失败");
e.printStackTrace();
}
return ipaddress;
}
在做支付的时候用到了。列出来,避免下次再找!