在Android模拟器WIFI网络获得计算机的IP地址 [英] get Ip address of computers in WIFI network on Android Emulator

查看:295
本文介绍了在Android模拟器WIFI网络获得计算机的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以编程方式找到它们通过WiFi连接到Android设备或仿真器的计算机的IP地址。我该怎么做呢?

I would like to programmatically find the IP addresses of computers which are connected via WiFi to an Android device or emulator. How do I do this?

推荐答案

可以共享logcat的,我怀疑可能有一些其他的issue.Try这个code(这是)一个示例应用程序来检查只有当无线网络连接的IP地址正在

Can you share the logcat, I suspect there might be some other issue.Try this code (as is) in a sample application to check only if Wi-Fi IP address is working

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();

int ipAddress = wifiInfo.getIpAddress();

String ip = null;

ip = String.format("%d.%d.%d.%d",
(ipAddress & 0xff),
(ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff),
(ipAddress >> 24 & 0xff))

这篇关于在Android模拟器WIFI网络获得计算机的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆