Android 앱에 setConnectionTimeout을 구현하고 싶습니다. 몇 가지 코드 구조를 따라 왔지만 제대로 작동하지 못했습니다. 내 응용 프로그램은 로컬 호스트 서버에 연결되어 있었지만 데이터베이스에 연결할 수없는 경우 연결 시간 제한을 표시하기 만하면됩니다.setConnectionTimeout 후 Android 앱이 다운 됨
여기 내 HTTP 요청 코드 :
HttpParams httpParameters = new BasicHttpParams();
// Set the timeout in milliseconds until a connection is established.
// The default value is zero, that means the timeout is not used.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
이 3 초, 응용 프로그램 충돌에 도달 할 때 문제입니다. 이 스 니펫을 구현하기 전에 오랫동안 정지되었습니다. Wi-Fi를 끄면 인터넷에 연결되어 있지 않다는 DialogBox가 반환됩니다. 이것이 내가 원하는 것입니다.
데이터베이스를 연결할 수없는 경우 AlertDialogBox를 반환하는 방법을 알려주세요. (이 목적을 위해 WAMP를 비활성화했습니다)
crashlog에 대한 logcat을 게시하십시오. –
다음은 logcat입니다 : http://pastebin.com/pS70UDe9 – AimanB