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.
protected static final int HTTP_JSON_TIMEOUT_CONNECTION = 20000;
protected static final int HTTP_JSON_TIMEOUT_SOCKET = 20000;
CloseableHttpResponse response = null;
try {
UserPrefs.clearCacheFolder(mContext.getCacheDir());
CloseableHttpClient httpClient = getApacheHttpClient();
HttpPost httpPost = getHttpPost( invocation);
response = httpClient.execute(httpPost);
}catch (Exception e){
e.printStackTrace();
}
protected CloseableHttpClient getApacheHttpClient(){
try {
// Socket config
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(HTTP_JSON_TIMEOUT_SOCKET)
.build();
// Auth
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(URL, PORT, null, "Digest"),
new UsernamePasswordCredentials(USERNAME,DIGEST_PASSWORD));
// Build HttpClient
return HttpClients.custom()
.setDefaultSocketConfig(socketConfig)
.setDefaultCredentialsProvider(credentialsProvider)
.build();
}catch (Exception e) {
Log.i("ApacheHttpClientHelper", "ERROR >> "+e.getMessage());
return null;
}
}
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"