繁体   English   中英

从另一个Android设备使用其热点获取Android设备的IP地址

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM