[英]Getting the IP Address of an Android Device using it's hotspot from another android device
我有两个启用了android
设备。在一个设备上,我打开了热点,而从另一台设备上,我正在连接到该热点。 现在,我想获取第一个设备的IP
地址。 我怎么才能得到它。 因为我想将文件发送到第一台设备,所以我需要该设备的IP
地址。我假设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());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.