retrofit2

Retrofit 2, same name different data type JSON Parsing

ⅰ亾dé卋堺 提交于 2019-12-01 21:52:01
I am trying to parse a JSON response from a server, If there are changes to in the query sent in post method I will get first one as response, if not I will get the second one as response. 1: { "status": 1, "data": { "firstname": "First Name", "lastname": "Last Name", "mobilenumber": "1234567894", "emailid": "test@gmail.com", "timezone": "Asia/Kolkata" }, "user_id": "", "response": "Profile Updated Successfully" } 2: { "status": 1, "data": "No changes to update", "user_id": "" } As you can see if there are changes the data returns a object, if there are no changes the data returns as string. I

Issue with Retrofit Response

别等时光非礼了梦想. 提交于 2019-12-01 20:22:46
I am trying to get List of States through Retrofit and trying to add in Searchable Spinner. What I get : I am getting List of States in Response. I can access one state in Spinner. What i want : I want to access multiple States in Spinner. Code : getMainApp().electAPI.getStates().enqueue(object : Callback<Responseval>{ override fun onFailure(call: Call<Responseval>, t: Throwable) { Toast.makeText(this@MainActivity, t?.message, Toast.LENGTH_SHORT) } override fun onResponse(call: Call<Responseval>, response: Response<Responseval>) { if (response.isSuccessful!!){ val states = response.body()?

Using RxJava 2 and Retrofit 2, adapter version issue

萝らか妹 提交于 2019-12-01 19:06:32
问题 I've added a new library module to existing application module in Android Studio. The main difference was adding RxJava 2 and Retrofit 2. After updating build.gradle of new module I started to get next error: Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForBetaNewApiDebug'. com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties File1: C:\Users\Gaket.gradle

POST Streaming Audio over HTTP/2 in Android

家住魔仙堡 提交于 2019-12-01 18:35:40
Some background: I am trying to develop a voice-related feature on the android app where a user can search using voice and the server sends intermediate results while user is speaking (which in turn updates the UI) and the final result when the query is complete. Since the server accepts only HTTP/2 single socket connection and Android HTTPUrlConnection doesn't support HTTP/2 yet, I am using Retrofit2. I have looked at this , this and this but each example has fixed length data or the size can be determined beforehand... which is not the case for audio search. Here's what my method for POST

Retrofit Closing Response Body

别说谁变了你拦得住时间么 提交于 2019-12-01 17:40:35
I've been getting this error: A connection to ****** was leaked. Did you forget to close a response body? So I went on and close the responses I get. response.body().close() Problem is if the response.body() is already converted to a custom class, there's no close method available. Also I tried calling raw and gives me an exception: fetchSomething.enqueue(new Callback<SomethingClass>() { @Override public void onResponse(Call<SomethingClass> call, Response<SomethingClass> response) { //Closes the response body response.raw().body().close(); //<--- gives illegalStateException } @Override public

How can I return data in method from Retrofit onResponse?

青春壹個敷衍的年華 提交于 2019-12-01 17:38:51
问题 I'm new with retrofit and I want to make my getData method to return a feature object. What is the easiest way to do that? DataService.java public class DataService { private static final String TAG = MainActivity.class.getSimpleName(); private final ApiClient apiClient; public DataService() { apiClient = new ApiClientFactory().createApiClient(); } public List<Feature> getData(){ apiClient.getData().enqueue(new Callback<DataResponse>() { @Override public void onResponse(Call<DataResponse>

How can I return data in method from Retrofit onResponse?

谁说胖子不能爱 提交于 2019-12-01 17:31:20
I'm new with retrofit and I want to make my getData method to return a feature object. What is the easiest way to do that? DataService.java public class DataService { private static final String TAG = MainActivity.class.getSimpleName(); private final ApiClient apiClient; public DataService() { apiClient = new ApiClientFactory().createApiClient(); } public List<Feature> getData(){ apiClient.getData().enqueue(new Callback<DataResponse>() { @Override public void onResponse(Call<DataResponse> call, Response<DataResponse> response) { List<Feature> features = response.body().getFeatures(); Log.d(TAG

Retrofit Closing Response Body

守給你的承諾、 提交于 2019-12-01 15:44:22
问题 I've been getting this error: A connection to ****** was leaked. Did you forget to close a response body? So I went on and close the responses I get. response.body().close() Problem is if the response.body() is already converted to a custom class, there's no close method available. Also I tried calling raw and gives me an exception: fetchSomething.enqueue(new Callback<SomethingClass>() { @Override public void onResponse(Call<SomethingClass> call, Response<SomethingClass> response) { //Closes

Retrofit logging interceptor exception

五迷三道 提交于 2019-12-01 13:45:49
问题 I am trying to enable Logging with Retrofit but I am getting this exception: 07-13 12:44:53.278 28698-29248/com.xxxx.debug E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher Process: com.xxxx.debug, PID: 28698 java.lang.NoSuchMethodError: No virtual method log(Ljava/lang/String;)V in class Lokhttp3/internal/Platform; or its super classes (declaration of 'okhttp3.internal.Platform' appears in /data/data/com.xxxx.debug/files/instant-run/dex/slice-realm-optional-api

Send Image file via Retrofit from Android to Spring

时光毁灭记忆、已成空白 提交于 2019-12-01 12:13:44
I am trying to upload Image via Retrofit to S3 via Spring. So, it's basically 2 tasks. Pass Image to Spring API From Spring API upload it to S3 Server. I know how to upload the Image to S3 and it works fine. My Problem is the first part. I have tried many solutions on net but didn't work.Here's my code -> On Android side, first I am Getting file and Uploading it to Spring API -> private void UploadFiles() { File uploadFile = fileArrayList.get(0); if (uploadFile != null) { Log.d(TAG, "UploadFiles: File Name is -> " + uploadFile.getName()); RequestBody requestFile = RequestBody.create(MediaType