Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to AVD

i'm trying to write my own android http server. It's quite OK but i have a problem with my AVD. I don't want to download my app to phone everytime I want to test changes. I would like to connect to my app via AVD. To get the ip address i'm using this function:

private String getLocalIpAddress() {


        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); }
                }
            }
        } catch (SocketException ex) {
            Log.e("ServerActivity", ex.toString());
        }
        return null;
    }

on my phone everything works good, but when i run my app on AVD it shows ip: 10.0.2.15 and i'm unable to connect to it. Is there any way to connect to my app running on AVD ? If it does matter my app uses port 8080.

like image 783
Gaski Avatar asked Sep 16 '11 15:09

Gaski


1 Answers

Telnet into the device (assuming it is on port 5554):

telnet localhost 5554

At the Android console prompt use a redirect:

redir add tcp:8080:8080

Pointing your browser to 'http://127.0.0.1:8080/' should now send, and receive to the AVD.

Courtesy of: http://www.rhill.co.uk/?p=35

like image 59
John Avatar answered Oct 10 '22 09:10

John