how to get ip address of pc in android emulator through code

江枫思渺然 提交于 2019-12-04 01:32:56

问题


i am using the code of this link How to get IP address of the device from code? but getting ip address different than from my machine....how can i get the ip address of my machine on android emulator..

thanks in advance


回答1:


Check this out if you want to access host machine.

Another solution is to run this on shell

$ adb shell am start -a android.intent.action.WEB_SEARCH -e query "what is my ip"

it will display your system IP




回答2:


import the package java.net;

and write the code,

try {
InetAddress thisIp =InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress());
}
catch(Exception e) {
e.printStackTrace();
}


来源:https://stackoverflow.com/questions/10118590/how-to-get-ip-address-of-pc-in-android-emulator-through-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!