Android 6.0 Httpclient Issue With Lg G3 Phone
Hi I am using DefaultHTTPClient class to create http request. The currrent code execute() method works on all phones including Nexus and Samsung with Android 6.0. But when i tested
Solution 1:
Ran into something similar and had a fix I'm trying that I added to another question
I ran into a similar issue today and just started using HttpClient for Android
- Added dependency
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
to build.gradle. - Replace
new DefaultHttpClient()
withHttpClientBuilder.create().build()
There are probably some other minor refactors you might need to make in other portions of the code, but that should be pretty straight forward.
Solution 2:
Give something like this a go, i had similar problem on MotoX running 6.0.1 but this seem to work for me.
protectedstaticfinalintHTTP_JSON_TIMEOUT_CONNECTION=20000;
protectedstaticfinalintHTTP_JSON_TIMEOUT_SOCKET=20000;
CloseableHttpResponseresponse=null;
try {
UserPrefs.clearCacheFolder(mContext.getCacheDir());
CloseableHttpClienthttpClient= getApacheHttpClient();
HttpPosthttpPost= getHttpPost( invocation);
response = httpClient.execute(httpPost);
}catch (Exception e){
e.printStackTrace();
}
protected CloseableHttpClient getApacheHttpClient(){
try {
// Socket configSocketConfigsocketConfig= SocketConfig.custom()
.setSoTimeout(HTTP_JSON_TIMEOUT_SOCKET)
.build();
// AuthCredentialsProvidercredentialsProvider=newBasicCredentialsProvider();
credentialsProvider.setCredentials(newAuthScope(URL, PORT, null, "Digest"),
newUsernamePasswordCredentials(USERNAME,DIGEST_PASSWORD));
// Build HttpClientreturn HttpClients.custom()
.setDefaultSocketConfig(socketConfig)
.setDefaultCredentialsProvider(credentialsProvider)
.build();
}catch (Exception e) {
Log.i("ApacheHttpClientHelper", "ERROR >> "+e.getMessage());
returnnull;
}
}
Also stick this into the gradle under dependencies
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
Post a Comment for "Android 6.0 Httpclient Issue With Lg G3 Phone"