Hi,
I had used java.net.HttpURLConnection or java.net.Socket to get a
image via HTTP protocol.
But it always got "java.net.SocketException : unknown error" message.
Why???
Does 0.9-SDK support network operation???
Thanks in advance.
Brad.
my code:
Bitmap bitmap = null;
InputStream in = null;
int response = -1;
try {
//we use URLConnection because it's anticipated
that it is lighter-
weight than HttpClient
//NOTE: At this time, neither properly support
connect timeouts
//as a consequence, this implementation will
hang on a failure to
connect
URL url = new URL("http://10.0.2.2/test.jpg");
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection)) throw
new
IOException("Not an HTTP connection.");
HttpURLConnection httpConn =
(HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
//httpConn.setConnectTimeout(CONNECT_TIMEOUT);
//httpConn.setReadTimeout(SOCKET_TIMEOUT);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect(); // <-- exceptoin occurs at
this line
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
}
} finally {
if (in != null) try {
in.close();
} catch (IOException e) {
/* ignore */
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---