我有两个android
启用设备。在一个设备上,我打开了热点,从其他设备上,我正在连接到该热点。现在,我想获得第一个设备的IP
地址。我怎么才能得到它。因为我想将文件发送到第一个设备,这就是为什么我需要该设备的IP
地址。我AM假设WifiManager
将用于此目的,但我不知道如何使用。我阅读了为此目的使用NetworkInterface
的其他线程。
- usman
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();)
{
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();enumIpAddr.hasMoreElements();)
{
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress())
return inetAddress.getHostAddress().toString();
}
}
}
catch (SocketException ex)
{
Log.e("ServerActivity", ex.toString());
}