Android Localhost?

此生再无相见时 提交于 2019-11-28 06:13:34

问题


I know this has been asked and answered before, but I use 10.0.2.2 for the emulator. And I heard I must use something else for my real device. Can someone tell me what that is? And can I have them both run off of 1 URL. Instead of having one for the emulator and actual device.


回答1:


Android Localhost?

localhost of an Android device is localhost, 127.0.0.1.

I use 10.0.2.2 for the emulator

That refers to localhost of the computer running the emulator.

And I heard I must use something else for my real device

You need to use the IP address of the computer, on whatever network that the computer and the device share. You cannot access localhost on one machine from another machine, by definition.

Of course, you also need to figure whatever it is that is running on that computer to listen to more than its own localhost.

Is there a way I can use a single IP Instead of using 10.0.2.2 for my emulator and having to use another one for my device

Not really. Moreover, neither of the values that you are thinking of are the right ones for a release build of your app, in all likelihood. There, you will need to use the domain name (or, in a pinch, IP address) of some publicly-visible server that everyone's devices can reach.




回答2:


You have to use the ip address of your computer for a real device.check your ip address and try to connect with it.In my case I came to know this when I was trying to access some webapp from my android device and my web application was on tomcat container on my pc.It worked very well for me.




回答3:


Get the ip address by running ipconfig from dos prompt and use it.



来源:https://stackoverflow.com/questions/21800939/android-localhost

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