I am using eclipse and the problem is that my httpConnection code is works for android 2.3.3. but it is not working for android 5.0 I cannot handle it.
private InputStream OpenHttpConnection(String urlString) throws IOException{
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if(!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try{
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if(response == HttpURLConnection.HTTP_OK){
in = httpConn.getInputStream();
}
}
catch(Exception ex){
throw new IOException ("Error connecting");
}
return in;
}
It gives me "Error connecting" on android 5.0 also android 4.0.3.
Since your describing that this error is not appearing when using android 2.3.3, it could have something to do with the new "Strict Mode".
When you're doing your network operations on the main thread, it could slow down or block the processing of the GUI which runs on the main thread. This would result in a non-responsive behaviour. Since API level 9, there is the so called "Strict Mode", which blocks such behaviour. Therefore you have to use a AsyncTask and run your network operations on a background thread. If you don't, you usually get such errors. As mentioned in the comment above - you should get more information about the thrown exception, in order to find out what the real problem is.
See also: stackoverflow post: cannot-connect-using-httpconnection-in-android
And to read more about AsyncTask: AsyncTask