Problem connecting to the web

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Problem connecting to the web

Postby misato » Wed Jan 07, 2009 12:02 pm

Hi!
I'm new at Android development. I'm making a small app just to understand how the SDK is. One of the task is connect to the internet and download a file. I've been searching here and lots of sites in google and i don't know what's my problem.
This is my code:
Code: Select all
try{
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod("GET");
            httpConn.connect();

            response = httpConn.getResponseCode();
            if (response == HttpURLConnection.HTTP_OK) {
                in = httpConn.getInputStream();
            }
        }
        catch (Exception ex)
        {
            throw new IOException("Error connecting");
        }

but it allways say: IOException: error connecting.
I'm not connecting to localhost (in case this would be a problem), and I'm using android sdk 1.0 rc2 over Windows with Eclipse and ADT 0.8.
Thanks for your help and sorry if this post is repeated but i can't understand why it isn't connecting even searching for similar problems.
PS: I've used code that was a solution for a similar problem but in my case, it doesn't work.
misato
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 07, 2009 11:55 am

Top

Postby misato » Mon Jan 12, 2009 12:00 pm

I've solved, just in case somebody has the same problem.
It was a permission issue, you have to set internet permission. In my case i've done it but in the wrong place.
Inside androidManifest.xml i've put it inside <application> tag but that's not the place.
You have to put it OUTSIDE, in the <manifest> tag like this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2.  
  3. <manifest>
  4.  
  5. <application>
  6.  
  7. ... code here ...
  8.  
  9. </application>
  10.  
  11.      <uses-permission android:name="android.permission.INTERNET"></uses-permission>
  12.  
  13. </manifest>
  14.  
  15.  
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


I hope this will help someone ;)
misato
Freshman
Freshman
 
Posts: 7
Joined: Wed Jan 07, 2009 11:55 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Google Feedfetcher and 5 guests