【发布时间】:2018-09-20 16:01:58
【问题描述】:
我已经将我的电脑有线连接到路由器,而我的安卓设备无线连接到同一个路由器。
我需要从我的应用程序访问在我的机器上运行的 nodejs 服务器。我需要在 Android 应用中检索机器的 IP 地址。
我试过这个代码
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
return ip;
ipconfig 命令显示 192.168.1.100,而在代码中它返回 192.168.1.103 ....如何让它在我的应用程序中获取机器的 IP 地址?
【问题讨论】:
-
I have connected my PC to wired Ethernet network。你的意思是你把你的电脑有线连接到你的路由器吗?whereas I am sharing PC network with android device through hotspot.。您的意思是您将 Android 设备无线连接到同一个路由器? -
I need to get the IP Address of my PC in Android studio.。 Android Studio 需要什么 IP 地址?我认为您设备上的 Android 应用想知道您 PC 的 ip。 -
But my network settings displays 192.168.1.100。这些是您PC的网络设置吗?你在哪里看到的? -
没错,我就是这个意思!!
-
whereas in code its returns 192.168.1.103。如果该代码在您的 Android 设备上运行,那么这就是您的 Android 设备的 ip。