ErrorCode=0,
ErrorMessage=com.androidnetworking.error.ANError: java.net.SocketTimeoutException
How I solve this problem, please?
@vsoft-phuong : You can pass custom okHttpClient with increased timeout.
OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.connectTimeout(120, TimeUnit.SECONDS)
.readTimeout(120, TimeUnit.SECONDS)
. writeTimeout(120, TimeUnit.SECONDS)
.build();
AndroidNetworking.initialize(getApplicationContext(),okHttpClient);
@vsoft-phuong : You can also customize it for a particular request.
OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.connectTimeout(120, TimeUnit.SECONDS)
.readTimeout(120, TimeUnit.SECONDS)
. writeTimeout(120, TimeUnit.SECONDS)
.build();
AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}")
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.addHeaders("token", "1234")
.setTag("test")
.setPriority(Priority.LOW)
.setOkHttpClient(okHttpClient) // passing a custom okHttpClient
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
// do anything with response
}
@Override
public void onError(ANError error) {
// handle error
}
});
Thanks you!
Please post a tutorial on uploading multipart files in background service and update ui progress.
@hiteshrawat
AndroidNetworking.upload(url)
.addMultipartFile("image",file)
.addMultipartParameter("key","value")
.build()
.setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
// do anything with progress
}
})
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
// do anything with response
}
@Override
public void onError(ANError error) {
// handle error
}
});
This code does uploading in background you can write this anywhere.
Thanks Amit I have tried it.Its working fine. But I want implement it with the Service and make it work even after exiting the app.
I am beginner to android.Please guide me.
@hiteshrawat : Sure sure I am here to help everybody.
You can write the same code in your service and then use LocalBroadcast to post progress from service to Activity . Example is present here
Thanks Amit
How to get the status code for Response?
@nikhiljadhav159 : refer this.
@amitshekhariitbhu How can i send multiple image and video in single request?
is it like
while(loop){
.addMultipartFile("image[]",file[i])
}
i am little confuse
my problem is "com.androidnetworking.error.ANError"
only show this error
Any one solve this problem
@amitshekhariitbhu what is maximum value can we set in the connectTimeout, readTimeout and writeTimeout?
Depends on you
@amitshekhariitbhu is there any standard/best practices to follow it...
@vsoft-phuong : You can pass custom okHttpClient with increased timeout.
OkHttpClient okHttpClient = new OkHttpClient().newBuilder() .connectTimeout(120, TimeUnit.SECONDS) .readTimeout(120, TimeUnit.SECONDS) . writeTimeout(120, TimeUnit.SECONDS) .build(); AndroidNetworking.initialize(getApplicationContext(),okHttpClient);
Does this code will work for Rx2AndroidNetworking???
@vsoft-phuong : You can pass custom okHttpClient with increased timeout.
OkHttpClient okHttpClient = new OkHttpClient().newBuilder() .connectTimeout(120, TimeUnit.SECONDS) .readTimeout(120, TimeUnit.SECONDS) . writeTimeout(120, TimeUnit.SECONDS) .build(); AndroidNetworking.initialize(getApplicationContext(),okHttpClient);Does this code will work for
Rx2AndroidNetworking???
Will this code work for all network calls used in the android project?? If the above is written in the Application class.
not working.
Most helpful comment
@vsoft-phuong : You can pass custom okHttpClient with increased timeout.