找我的无线IP地址的Android [英] Get my wifi ip address Android
本文介绍了找我的无线IP地址的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能得到我的电话的IP地址时,它在无线连接?
How can I get the ip address of my phone when it is connected under wifi?
我发现了一个方法这里但返回像24.182.239.255即使我在WiFi和我希望是这样192.168.1.10。
I found a method here but it returns something like 24.182.239.255 even if I'm under wifi and I expect something like 192.168.1.10.
我想是这样的:
if (you are under wifi)
String ip4 = getWifiIP()
else
String ip4 = getIPAddress with the method linked before
非常感谢!
推荐答案
如果你想获得设备的私有IP地址时,连接到Wi-Fi,你可以试试这个。
If you would like to get the private IP address of your device when connected to Wi-Fi, you can try this.
WifiManager wifiMgr = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipAddress = Formatter.formatIpAddress(ip);
一定要添加的权限
Be sure to add the permission
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
你的清单。
这篇关于找我的无线IP地址的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文