📜 ⬆️ ⬇️

Android Emulator and local web server (Denwer)

image I will continue to share some development cases for Android and now I want to talk about how easy it is to make an application running in the emulator work with your own server API, which lies on the local web server. In simple words - how to communicate to the application from the emulator via http with localhost. This is not professional advice, and no more than an example of a specific working solution.

I'll start with the conditions of the problem. My application, which I described last time , needed the ability to publish pictures on the phone in an online gallery. In my case, the gallery is its own website, which in a POST request receives an image and some text variables. Denwer is running on a windows-machine to emulate a web server, access to the gallery project via http is organized by urlu _http: //dev.gallery.
And so, the problem is that the emulator does not see your own hosts with host descriptions and, therefore, does not know about _Http: //dev.gallery. Attempts to place the project in localhost / dev.gallery also do not lead to anything, since 127.0.0.1 for the emulator is himself. The problem is solved by making changes to the emulator hosts. Specifically - lines 10.0.2.2 dev.gallery . This address should be used if you want to access the services hosted on your machine. A complete list of address space addresses is here .
In order to make the appropriate changes:


After that you can safely knock on your web server. If you restart the emulator, the hosts will have to be replaced again. To speed up the work, it is convenient to create and use one cmd-file, which starts the emulator with the necessary parameters and the second one, replacing the hosts with the previously prepared ones if necessary.

All this was used to debug the work of the PaintUp application and the PaintUp.net gallery .

')

Source: https://habr.com/ru/post/120671/


All Articles