How can I let android emulator talk to the localhost?
I'm running an and开发者_StackOverflow中文版roid app on the emulator. This app tries to load a html file using the webview api.
I also have a simple http server running on the same computer under the directory where I want to serve the request using the following python command:
python -m SimpleHTTPServer 800
However, I couldn't access this link through either the app or the browser on the emulator:
http://localhost:800/demo.html
Please let me know if I'm missing something.
Use address 10.0.2.2 instead of localhost.
localhost is a short-cut to tell the "whatever" to talk to itself. So, you are telling the emulator to look for a web server running in the emulator.
Instead of trying to connect to localhost, look up the IP for your computer and use that instead.
Actually localhost refers to the emulators directory itself.
Use your system ip to access the link
Best solution is not to use emulator at all. Its slow and full of bugs. Get your employer to buy a device or two.
精彩评论