2

My android emulator can't access the internet. It is connected to the "network". It can see machines/servers in the local network, but nothing beyond that. I can see the 3g icon at the top right.

From my code I'm trying to download something from a server on the Internet and I'm getting UnknownHostException. I have the android.permission.INTERNET set in the manifest, but obviously that is not the issue since not even the OS's browser can open websites. I think I can't expect my code to be able to access the Internet if not even the browser can.

After all my googling most people keep talking about configuring a proxy, but I'm not connected to the internet using a proxy in the computer. Is this something that needs to be set up anyway ? Any other settings that need to be checked ?

bluediapente
  • 3,946
  • 5
  • 32
  • 38

3 Answers3

4
  • Do you have more than one network card in your computer? (ie an ethernet and wireless)? If so, go into your network settings and disable the one you aren't using. Even if its not currently connected to anything.

  • Do you use something like Norton Internet Security? If you disable it, does the emulator internet work?

  • You also might have a DNS issue: you can try within Eclipse ->Run
    Configurations -> Target and add
    "-dns-server X.X.X.X" where X.X.X.X
    was the IP address for your DNS
    server.

  • If win7, start emulator with admin
    privledges

  • on mac, If you are on Mac - try
    this -

    1.GoTo Apple Icon -> System Preferences -> Network 2.Click on the gear icon on the and select 'Set Service Order' 3.Bring the active interface before other interface. 4.Restart the Android Emulator.

    and other useful things to try from: How to connect android emulator to the internet

Community
  • 1
  • 1
jkhouw1
  • 7,320
  • 3
  • 32
  • 24
-1

I recently wrote an app which downloaded a ringtone off the internet and saved it in the sdcard. I'm pasting the code here so maybe you can compare

            url = new URL("http://wap.iwfr.net/mp3/mp3toringtone/mp3file-"+id+".mp3");
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        int responseCode =conn.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            InputStream in = conn.getInputStream();
            int size = in.available();
            byte[] buffer = new byte[size];
            in.read(buffer);

            in.close();



            String path="/sdcard/sounds/";
            String filename="fahad.mp3";
            boolean exists = (new File(path)).exists();
            if (!exists){new File(path).mkdirs();}
            FileOutputStream save;
            save = new FileOutputStream(path+filename);
            save.write(buffer);

            save.flush();
            save.close(); }
-1

The answers to my question Upgraded to SDK 2.3 - now no emulators have connectivity might be of use.

Community
  • 1
  • 1
NickT
  • 23,844
  • 11
  • 78
  • 121