我创建的应用程序,Xperia Active和Xperia SX中经常出现异常。 (有ICS 4.0.4设备)。
09-07 13:11:56.755: W/System.err(2012): Caused by: java.net.SocketTimeoutException
09-07 13:11:56.765: W/System.err(2012): at java.net.PlainSocketImpl.read(PlainSocketImpl.java:491)
09-07 13:11:56.765: W/System.err(2012): at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
09-07 13:11:56.765: W/System.err(2012): at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
09-07 13:11:56.765: W/System.err(2012): at java.io.InputStream.read(InputStream.java:163)
09-07 13:11:56.765: W/System.err(2012): at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
09-07 13:11:56.765: W/System.err(2012): at java.io.BufferedInputStream.read(BufferedInputStream.java:227)
09-07 13:11:56.765: W/System.err(2012): at libcore.io.Streams.readAsciiLine(Streams.java:201)
09-07 13:11:56.765: W/System.err(2012): at libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:544)
09-07 13:11:56.775: W/System.err(2012): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:791)
09-07 13:11:56.775: W/System.err(2012): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
09-07 13:11:56.775: W/System.err(2012): at libcore.net.http.HttpURLConnectionImpl.getResponseMessage(HttpURLConnectionImpl.java:475)
使用HttpURLConnection,应用程序非常简单。
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
urlConnection.setRequestMethod("POST");
urlConnection.connect();
String responseMessage = urlConnection.getResponseMessage();
int responseCode = urlConnection.getResponseCode();
final String contentType = connection.getContentType();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
in.close;
} catch (Exception e) {
e.printStackTrace();
} finally {
urlConnection.disconnect();
}
您不能在其他供应商的ICS设备上发生异常。 我不认为应用程序的问题。 有没有解决方法或什么?