During developing mobile web application for android platform it would be nice that you are able to test it. For testing purpose, if you don't have android phone, you can use Android emulator which is included in Android SDK.
During testing you will need to access application hosted on your local machine, but typing of "localhost" or "127.0.0.1" will not lead you to your web server, on your developing machine (emulator host), instead you will get message that Page is not available. Accessing web application on your emulator host can be done by typing 10.0.2.2 in web browser on your android emulator. But in some cases accessing by IP address is not preferred way, eg when you host more pages on the same server.
Currently I am working on developing application which use OpenCMS. OpenCMS is able to host more sites in the same time, so in my case every customer have it's own web site on the same server. But direct access with IP address will lead me to see my JBoss, and i will not be able to see pages of some particular customer.
To resolve this problem you can use Android Debug Bridge.
First i started emulator and used pull command to get "hosts" file from android device.
./adb pull system/etc/hosts hosts
This will copy content of hosts file from emulator to your PC. After that I added one new line of code and copy changed file to emulator.
127.0.0.1 localhost
10.0.2.2 blau vam rot pvr
First time when I tried to copy file back to the emulator, I got the message that there is no more free space on emulator. Solution of this problem is starting device with more space the default, it can be done with next command:
./emulator -partition-size 128 @Android &
After that i was able to run push command without any problems, of course after mounting system with read and write permission.
In next few lines you can see simple script used for starting emulator with prepared "hosts" file.
#!/bin/bash
echo "Starting Android 2.2 Emulator..."
./emulator -partition-size 128 @Android &
echo "Emulator started.\n Configuring device."
../platform-tools/adb wait-for-device remount
../platform-tools/adb wait-for-device push ../platform-tools/hosts system/etc/hosts
echo "Device configured."
I am happy to find this post Very useful for me, as it contains lot of information. I Always prefer to read The Quality and glad I found this thing in you post. Thanks emulator androida
ReplyDelete