4

When attempting to open a connection on the android 2.1 platform, the HttpUrlConnection.getInputStream method always throws a IOException, FileNotFound exception. The code works as expected in 2.2 and 2.3 version of Android. I have a standard method for creating a new connection. The error is thrown immediately after this when get input stream is called. As a note, all of the connections attempting to be made are "http://something/something".

public static URLConnection createConnection(String urlStr, Boolean useAuthentication, Boolean setOutput){
        Log.i(GpodRoid.LOGTAG, "Creating Connection to " + urlStr);
        URLConnection conn = null;
        try {
            conn = new URL(urlStr).openConnection();
            conn.setDoOutput(setOutput);
            conn.setDoInput(true);

            if(useAuthentication){
                String auth = GpodRoid.prefs.getUsername() + ":" + GpodRoid.prefs.getPassword();
                String encoded = Base64.encodeBytes(auth.getBytes());
                conn.setRequestProperty("Authorization","basic " + encoded);
            }
        } 
        catch (Exception e) {
            Log.e(GpodRoid.LOGTAG, "Error creating Connection: " + stackTrace(e));
        } 

        return conn;
    }

1 Answer 1

1

If it opens the connection on 2.1 - I don't see a reason why it shouldn't work on > 2.1.

Could it be a missing permission in your Android.manifest. If yes, have you tried this ?

Sign up to request clarification or add additional context in comments.

1 Comment

Okay. If you figure out the solution, do post it so others can find it useful. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.