retrofit2

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

只愿长相守 提交于 2019-12-04 07:39:24
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 broken file. This is how I record the audio: private void startRecordingAudio() { Log.d("audiorecording",

Android Unit Test with Retrofit2 and Mockito or Robolectric

帅比萌擦擦* 提交于 2019-12-04 07:28:31
问题 Can I test real response from retrofit2beta4? Do i need Mockito or Robolectic? I don't have activities in my project, it will be a library and I need to test is server responding correctly. Now I have such code and stuck... @Mock ApiManager apiManager; @Captor private ArgumentCaptor<ApiCallback<Void>> cb; @Before public void setUp() throws Exception { apiManager = ApiManager.getInstance(); MockitoAnnotations.initMocks(this); } @Test public void test_login() { Mockito.verify(apiManager)

OkHttp 3 response cache (java.net.UnknownHostException)

≯℡__Kan透↙ 提交于 2019-12-04 07:09:42
问题 I'm really stuck at this problem. I want to cache server response for some time to use the data when device is offline. So I set a cache to my OkHttpClient . Also I set Cache-Contlol header. Here is my code: public class MainActivity extends AppCompatActivity { Retrofit retrofit; RecyclerView recyclerView; RandomUserAdapter mAdapter; Cache cache; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity

I having the two json response from the server side with the same “key”.The json is posted below

前提是你 提交于 2019-12-04 07:01:24
问题 {"data": { "userId":"+919923911289", "inTime":"2016-07-25 12:09:47+05:30", "outTime":"0", "totalTime":"0", "type":"attendance" } } And the second json response is {"data":"please try again..."} I am using retrofit to get the response . For the first json i have created the Gson model.But , when the response is in the second json format i didn't have any response model for it. I am displaying the data using the GsonModel for the first json response. And if there is second type of response what

Why does my activity doesn't see an observed object change?[SOLVED]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 05:47:58
问题 I'm new to Android development and i am trying to understand Live Data with MVVM architecture. I am trying to make the main activity recognize when there is a change in an object that belong to the view-model of the activity. I have created a simple login activity that takes the text from the username and password fields and passes them to the view-model's login function, then the function sends the data to the users repository and then it makes a POST request toa spring-server that is

Retrofit Offline cashing returns a null response.body()

雨燕双飞 提交于 2019-12-04 05:16:03
问题 I tried this link and this link to construct an offline Retrofit cache. The problem is that if I put the phone in Airplane mode, the Response.body() is always null. Here's my code: OkHttpClient client = new OkHttpClient .Builder() .cache(new Cache(App.sApp.getCacheDir(), 10 * 1024 * 1024)) // 10 MB .addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); if (App.isNetworkAvailable()) { request = request

How to provide Context with Dagger2

半世苍凉 提交于 2019-12-04 04:46:23
问题 I am learning Android and I am following some guides for Retrofit2 with RxJava and Dagger2. Now I want to handle no internet connection case. I've found this answer, which seems to be elegant, but I do not understand how to apply it. I've got some NetworkModule , with OkHttpClient provider. I assume I need to create OkHttpClient.Builder with interceptor. So it should look something like this: ` @Provides @Singleton OkHttpClient provideOkHttpClient(Cache cache) { ConnectivityInterceptor ci =

Receiving incomplete response from retrofit

自作多情 提交于 2019-12-04 03:21:32
问题 I am using retrofit version 2.6.1 for making http requests over the network. The JSON I am expecting is 42466 characters long. However, I am receiving only 4073 characters and API are working fine on web browser and postman. So I added custom okhttp client and increase timeout but it does not help me. private var okHttpClient: OkHttpClient = OkHttpClient().newBuilder() .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(10, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS) .build() Then I

Retrofit 2 synchronous call error handling for 4xx Errors

假如想象 提交于 2019-12-04 03:18:51
I'm using a android-priority-jobqueue and I use retrofit to make synchronous calls to my rest api but i'm unsure how to handle errors like 401 Unauthorized errors which I send back json stating the error. Simple when doing async calls but I'm adapting my app for job manager. below is a simple try catch for IO exceptions, but 401's 422's etc? How to do this? try { PostService postService = ServiceGenerator.createService(PostService.class); final Call<Post> call = postService.addPost(post); Post newPost = call.execute().body(); // omitted code here } catch (IOException e) { // handle error }

How to make a POST request using retrofit 2?

纵饮孤独 提交于 2019-12-04 03:08:18
问题 I was only able to run the hello world example (GithubService) from the docs. The problem is when I run my code, I get the following Error, inside of onFailure() Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $ My API takes POST params value, so no need to encode them as JSON, but it does return the response in JSON. For the response I got ApiResponse class that I generated using tools. My interface: public interface ApiService { @POST("/") Call<ApiResponse>