Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
986 views
in Technique[技术] by (71.8m points)

url - Android Localhost?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...