I didn't find the right solution. The below code gives me local IP address (if I connected to Wifi, it gives IP address like 192.168.0.x), but I want public IP address (same as if I search in google " what is my IP ")public static String getLocalIpAddress() {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() && inetAddress instanceof Inet4Address) { return inetAddress.getHostAddress(); } } }} catch (SocketException ex) { ex.printStackTrace();}return null;} ORWifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE); String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());任何人都可以帮忙吗?谢谢!Can anyone help? Thanks!推荐答案步骤1:创建一个返回请求者IP地址的Web服务Step #1: Create a Web service that returns the requester's IP address步骤2:从您的应用中调用该Web服务.Step #2: Call that Web service from your app.设备不知道其公共IP地址(除非该设备严重配置错误).A device does not know its public IP address (unless that device was seriously misconfigured). 这篇关于如何以编程方式获取公共IP地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-06 10:39