retrofit2

How can I set connection timeout in Retrofit library for Android?

只谈情不闲聊 提交于 2019-12-06 04:53:43
I have used Retrofit library for my Android application.I need to set connection timeout as 120 Sec. How can I do ? Version: compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0' compile 'com.google.code.gson:gson:2.8.0' compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' OperatingApiClient: public class OperatingApiClient { public static final String BASE_URL = "http://172.16.2.39/"; private static Retrofit retrofit = null; public static Retrofit getClient() { if (retrofit==null) { retrofit = new Retrofit.Builder() .baseUrl(BASE_URL)

Retrofit uploading a picture

喜夏-厌秋 提交于 2019-12-06 04:23:23
问题 I'm using Retrofit v.2.2.0 to upload a picture to my server but the server returns a null value stating no image has been uploaded. The logs shows the image is uploaded and the file name is correct when uploaded. What can be the problem yet it works in postman? UploadProfilePicture.java public class UploadProfilePicture extends ContextWrapper { private GetOnUpload onUpload; private File imageFile,filesDir,file; private Uri fileUri; private String profilePic = "profile_pic"; private String

How to set dynamic filename?

假装没事ソ 提交于 2019-12-06 04:18:46
Using retrofit 2, how would I set a dynamic name for the uploaded file? Currently, it's like this: @Part("avatar\"; filename=\"image\" ") RequestBody image, However, the uploaded file name would be image without the extension. Any recommendation on this case? Define your endpoint with MultipartBody.Part as the type: interface Example { @Multipart // @POST("/foo/bar/") // Call<ResponseBody> method(@Part MultipartBody.Part part); } and then use its factories to create the type: RequestBody body = // image body... Call<ResponseBody> call = example.method( MultipartBody.Part.createFormData("image"

Dagger 2 injecting two retrofit objects

℡╲_俬逩灬. 提交于 2019-12-06 03:55:59
I'm using Dagger 2 with retrofit2 library while using MVP. Everything went well till I tried to integrate another service (basically I tried to initialize another retrofit object to another service). I followed this answer but without any success. Every time I'm getting an errors that each of my fragments and application classes don't seem to recognize the component classes. error: cannot find symbol class DaggerApplicationComponent error: cannot find symbol class DaggerEpisodeComponent Code ApplicationComponent @Singleton @Component(modules = ApplicationModule.class) public interface

Audio file captured by MediaRecorder is broken after it is sent to server using Retrofit 2

百般思念 提交于 2019-12-06 03:32:56
问题 My app records an audio clip and send the clip to the server using Retrofit2 after the recording is completed.The file is received in server,but the file is broken,what I mean by broken is that it cannot be played. I use the following URL(example url: mydomain.co/audio/myaudio.mp4 ) to play the audio clip,which I tried with another audio file using postman ,the audio file can be played successfully.Besides,even downloading the audio clip captured by android via Filezilla also has the same

Retrofit 2 + RxAndroid: Handle Errors (4xx and some 200)

冷暖自知 提交于 2019-12-06 02:31:29
I saw a lot of articles and questions about error handling using retrofit combined with RxAndroid, but i am not able to set my configuration right. What do I want to accomplish: when receiving a 4xx code: handle it on onError() when receiving a 2xx code: -> try to parse to expected response and deliver it onNext() -> If not possible try to convert the JSON answer to MyAPIError class (simple POJO with errorNum and message) and deliver it on onError. So either 2xx or 4xx http codes might end up in onError(). What do I have at the moment: ServiceGenerator.java public class ServiceGenerator {

Retrofit2 post method showing server internal error but postman giving response

与世无争的帅哥 提交于 2019-12-06 02:11:27
I am very new to retroft. I am using retrofit2 for my API integration. I have an API for POST method. I am sending the body from postman and I am getting response, but when I am doing this programatically I am getting "Internal Server Error". This is my post man response And my code is private void savePost(String post_body, String permission, String latitude, String longitude, String location) { try { Retrofit retrofit = new Retrofit.Builder() .baseUrl(BuildConfig.BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); ApiService api = retrofit.create(ApiService.class); /** *

ExceptionInInitializerError in Okhttp.Builder w/ Multidex & Kitkat

旧巷老猫 提交于 2019-12-06 01:41:24
问题 I'm experiencing an ExceptionInInitializerError exception on VM running Kitkat 4.4.2 with Multidex enabled. java.lang.ExceptionInInitializerError at okhttp3.OkHttpClient.newSslSocketFactory(OkHttpClient.java:263) at okhttp3.OkHttpClient.<init>(OkHttpClient.java:229) at okhttp3.OkHttpClient$Builder.build(OkHttpClient.java:1015) at myapp.utils.Utils.getHttpClientBuilder(Utils.java:131) at myapp.fragments.FragmentHome.getHome(FragmentHome.java:326) at myapp.fragments.FragmentHome.onViewCreated

Retrofit 2.0 multipart

跟風遠走 提交于 2019-12-05 20:27:17
I have working OkHttp MultiPart request : multi = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart("email", m) .addFormDataPart("password", p) .addFormDataPart("user_name", n) .addFormDataPart("user_phone", phone) .addFormDataPart("photo", "avatar.jpg", RequestBody.create(MediaType.parse("image/jpg"), imgToArray(bmpChosenPic))) //.addFormDataPart("photo", "1") .build(); request = new Request.Builder() .url(Utils.TEST_BASE_URL + "" + REG_URL) .post(multi) .build(); client.newCall(request).enqueue(new Callback()... Now I try to make the same function using Retrofit 2.0 .

Retrofit generic response handler

巧了我就是萌 提交于 2019-12-05 20:24:06
I wish to handle all my responses in single method. the purpose is to recall the service when the response code is not 3, when the response code is 3 I intend to first refresh the token and then recall the same service. I've created a Basecallback class to catch one method but I can't see the log and can't catch breakpoints. BASECALLBACK.class public class BaseCallBack<T> implements Callback<T> { @Override public void onResponse(Call<T> call, Response<T> response) { if (!response.isSuccessful()){ Log.d("BaseCallback","Response Fail"); } } @Override public void onFailure(Call<T> call, Throwable